This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54
- From: Tom Honermann <thonermann at coverity dot com>
- To: <cygwin at cygwin dot com>
- Date: Wed, 15 Jan 2014 11:39:56 -0500
- Subject: Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54
- Authentication-results: sourceware.org; auth=none
- References: <831845 dot 98759 dot bm at smtp116 dot sbc dot mail dot ne1 dot yahoo dot com>
On 01/13/2014 11:06 AM, tednolan@bellsouth.net wrote:
...
switch (fork()) {
/* error */
case -1:
...
/* child */
case 0:
fprintf(stderr, "child\n"); fflush(stderr);
exit(0);
break;
The above code is incorrect. It is always wrong to call exit() from a
forked process that has not yet called one of the exec() family of
functions. _exit() should be called instead. Best case, calling exit()
will result in double flushing of any stream buffers held by the parent
at the time fork() is called (since the buffers will (eventually) be
flushed by the parent as well as the child (unless at least one of the
processes aborts or exits with _exit()).
Tom.
--
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