Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Feb 2005 11:32:39 +0000 (GMT)
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Daniel Eischen <deischen@freebsd.org>
Cc:        alfred@freebsd.org
Subject:   Re: POSIX semaphores and fork() -- when any process exits, they all lose , access
Message-ID:  <Pine.NEB.3.96L.1050225104949.24292C-100000@fledge.watson.org>
In-Reply-To: <Pine.GSO.4.43.0502241457060.22326-100000@sea.ntplx.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.NEB.3.96L.1050225104949.24292C-100000>