Synchronization problem with posix_spawn

Corinna Vinschen corinna-cygwin@cygwin.com
Thu Jul 30 11:59:13 GMT 2020


On Jul 29 19:12, Ken Brown via Cygwin wrote:
> On 7/29/2020 4:17 PM, Ken Brown via Cygwin wrote:
> > posix_spawn(p) returns before the spawned process is fully up and
> > running.  [...]
> I just took a look at the source, and I see that posix_spawn was taken from
> FreeBSD.  Does FreeBSD have the same problem?  Should applications just be
> aware of this issue and insert a sleep after posix_spawn before sending
> signals?

Actually, this is a Cygwin problem.  I just had a look into the
newlib implementation myself, and it turns out that the code,
in particular the do_posix_spawn() function, is BSD specific.  It
relies on the BSD implementation of vfork(2).  Cygwin's vfork(2)
on the other hand, is NOT following the historic idea of the
BSD vfork(2), rather it's equivalent to fork(2).  This is
POSIX compliant, but certainly the reliance of the BSD vfork
behaviour makes do_posix_spawn() as it's implemented right now,
not overly functional for Cygwin.

IOW, we need a Cygwin-specific do_posix_spawn() using fork(2)
in conjunction with some synchronization the BSD function
gets "for free" by using its specific vfork(2).


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer


More information about the Cygwin mailing list