POSIX semaphores and fork() -- when any process exits, they all
lose , access
Robert Watson
rwatson at FreeBSD.org
Fri Feb 25 03:34:26 PST 2005
On Thu, 24 Feb 2005, Daniel Eischen wrote:
> > If I create a named POSIX semaphore in a process, then fork(), the
> > semaphore appears to be visible to both the parent and child. However, as
> > soon as the child exits, the semaphore disappears from the parent. This
> > seems likely incorrect, although I don't have a copy of the spec in
> > question so couldn't say for sure.
>
> http://www.opengroup.org/onlinepubs/009695399/functions/sem_open.html
Hmm. I haven't yet found a reference to fork() semantics for semaphores
in the semaphore-related pages. However, a bit of googling turned up the
following references:
- HIP's Tru64 documentation includes the words:
"The semaphore descriptor is inherited across a fork. A parent process
can create a semaphore, open it, and fork. The child process does not
need to open the semaphore and can close the semaphore if the
application is finished with it."
So it sounds like the semaphore references for a process basically need to
be replicated for the child. One hesitates to guess how this will
interact with things like Linux threading. The glibc POSIX semaphores
documentation doesn't mention sem_open()/sem_close(), so maybe they only
do semaphores in the context of the user thread library, and not
inter-process semaphores.
Thanks,
Robert N M Watson
More information about the freebsd-threads
mailing list