This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Bug in fork() while in a thread


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.


Attachment: forktestcase.c
Description: Text document

--
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]