This is an extract from Advanced Liniux Programming:
Semaphores continue to exist even after all processes using them have terminated.
The last process to use a semaphore set must explicitly remove it to ensure that the
operating system does not run out of semaphores.To do so, invoke semctl with the
semaphore identifier, the number of semaphores in the set, IPC_RMID as the third argument,
and any union semun value as the fourth argument (which is ignored).The
effective user ID of the calling process must match that of the semaphore’s allocator
(or the caller must be root). Unlike shared memory segments, removing a semaphore
set causes Linux to deallocate immediately.
If a process allocate a shared memory, and many process use it and never set to delete it (with shmctl), if all them terminate, then the shared page continues being available. (We can see this with ipcs).
If some process did the shmctl, then when the last process deattached, then the system will deallocate the shared memory.
So far so good (I guess, if not, correct me).
What I dont understand from that quote I did, is that first it say:
"Semaphores continue to exist even after all processes using them have terminated."
and then:
"Unlike shared memory segments, removing a semaphore set causes Linux to deallocate immediately."