Native posix_spawn() in Cygwin?

Dan Shelton dan.f.shelton@gmail.com
Tue Mar 5 22:42:00 GMT 2024


On Mon, 4 Mar 2024 at 07:45, Mark Geisert via Cygwin <cygwin@cygwin.com> wrote:
>
> On 3/3/2024 7:27 PM, Dan Shelton via Cygwin wrote:
> > On Tue, 27 Feb 2024 at 07:34, <gs-cygwin.com@gluelogic.com> wrote:
> >>
> >> On Tue, Feb 27, 2024 at 06:54:42AM +0100, Dan Shelton via Cygwin wrote:
> >>> On Tue, 27 Feb 2024 at 06:47, Brian Inglis via Cygwin <cygwin@cygwin.com> wrote:
> >>>>
> >>>> On 2024-02-26 20:23, Dan Shelton via Cygwin wrote:
> >>>>> Does Cygwin implement a native, i.e. without form(),exec(), implementation of posix_spawn()?
> >>>>
> >>>> Check the API compatibility docs online:
> >>>>
> >>>>          https://cygwin.com/cygwin-api/compatibility.html#std-susv4
> >>>>
> >>>> or optional locally installed package cygwin-doc:
> >>>>
> >>>>          /usr/share/doc/cygwin-doc/html/cygwin-api/compatibility.html#std-susv4
> >>>
> >>> That document does not answer my question.
> >>>
> >>> I know posix_spawn() is there. But the question is: Does it use just
> >>> Cygwin fork(),exec(), or the native Win32 spawn() api?
> >>>
> >>> Dan
> >>> --
> >>> Dan Shelton - Cluster Specialist Win/Lin/Bsd
> >>
> >> If you were going to make a small effort to answer the question
> >> yourself, you could use strace, you could step through a debugger, or
> >> you could check the source code.  Have you tried any of these?  What did
> >> you find?  If you are unable to take any of those steps, why does
> >> posix_spawn() matter to you?
> >
> > strace does not help, as I need the Win32 calls BELOW posix_spawn(),
> > to see the implementation details.
>
> Check the source code, then. It's at:
>      https://cygwin.com/cgit/newlib-cygwin/tree/winsup/cygwin/fork.cc
>
> Look at line 587; there's the static function dofork(). Look at the
> thirty or so lines above that; there's both fork() and
> __posix_spawn_fork() calling dofork(). So both those user-level
> functions call into the exact same internals. (BTW __posix_spawn_fork()
> is called from posix_spawn(); the latter is in newlib and not Cygwin.)
>
> You can even see the reason it's done this way by reading the comment.

Yes, but it is as I feared, Cygwin posix_spawn() does not use Win32
spawn() at all, and instead uses a rather inefficient vfork()
solution.

posix_spawn() was added to POSIX so a Win32 implementation can use Win32 spawn()

Dan
-- 
Dan Shelton - Cluster Specialist Win/Lin/Bsd


More information about the Cygwin mailing list