开发者

Shared Memory and Process Sempahores (IPC)

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."


The two statements don't contradict each other...

The first statement says that the semaphore will continue to exist unless/until some program explicitly deletes it (i.e. it won't be auto-deleted when the last program stops using it).

The second statement says that when a program deletes a semaphore set, linux will deallocate the semaphore set immediately (as opposed to, say, waiting for all other programs to stop using it first)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜