Bug in fork() while in a thread

Jason Curl jcurlnews@arcor.de
Sun Aug 15 17:42:00 GMT 2010


Hello,

Is it allowed to issue the fork() system call while not in the main 
thread? When I read the OpenGroup specifications I don't seem to find 
anything against allowing this.

In particular, if I create a thread, then issue a fork(), data that 
exists on the stack is corrupted after the fork() is in the child. Using 
data on the heap doesn't show any issues (and is currently my 
workaround, in case this is a bug).

I've created a minimal example:
$ gcc -g -O0 forktestcase.c -o forktestcase.exe
$ ./forktest
Pointer BEFORE THE FORK env is 0x28cd00
This is the child
Pointer env is 0x28cd00
  env[0] is
  env[1] is
Child exited with 0

Further, a stackdump is now present, probably while iterating through 
the null terminated array at 0x28cd00 after the fork().

If you have a look at the attached code, I believe the expected output is
$ ./forktest
Pointer BEFORE THE FORK env is 0x28cd00
This is the child
Pointer env is 0x28cd00
Child exited with 0

This bug is not recreatable if we execute fork() in the main thread and 
not a separate thread.

Please find attached the test case.


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: forktestcase.c
URL: <http://cygwin.com/pipermail/cygwin/attachments/20100815/fbaf8715/attachment.c>
-------------- next part --------------
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


More information about the Cygwin mailing list