Forking Win32 process?

Dmitry Bely
Sun Jan 27 10:43:00 GMT 2008

Having read the FAQ chapter "How do I use cygwin1.dll with Visual
Studio or MinGW"
I am trying to load cygwin1.dll and then call fork(). This is not
going to work: it creates the child process but then hangs somewhere
inside cygwin1.dll. As the docs didn't tell it's impossible I
suspected my own error and spent a significant amount of time trying
to make it work. Several problems were found:

- the FAQ statement "Make sure you have 4K of scratch space at the
bottom of your stack" is simply wrong. You have to reserve at least
CYGTLS_PADSIZE (currently 12700 bytes) in the bottom of the stack.
Also they cannot be reserved at the very bottom - several hundred
bytes (300 or so) are taken by the CRT data. If it's OK it should be
explained somethere (in the FAQ or in cygload sources)

- even current cygload utility works somewhat incorrectly in my system
(WinXP). It does not hang or generate access violation (all cygwin
function succeed in debugger), but all output after loading
cygwin1.dll goes to nowhere, i.e. "Initializing cygwin..." is the last
message I see on the screen.

OK, but I needed fork(). I tried almost everything, even switching
stack (changing TIB) - nothing helped. And finally I found the
following message from Christopher Faylor of December, 2000:
You need to call "cygwin_dll_init" (via GetProcAddress of course) prior
to using any cygwin functions.  This function takes no arguments.

This doesn't mean that you'll be able to call every single cygwin
function.  Some, like fork() won't work.

Ah, is it up-to-date info and fork() really doesn't work with the
current cygwin? If so, why this is not mentioned in the docs or
somewhere? Is it really impossible from the technical point of view?

- Dmitry Bely

More information about the Cygwin-developers mailing list