On Jan 15 11:39, Tom Honermann wrote:
> On 01/13/2014 11:06 AM, tedno...@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()).

Still, SUSv4 says:

  The exit() function shall then flush all open streams with unwritten
  buffered data and close all open streams. Finally, the process shall
  be terminated [...]
 
Note that exit only flushes streams with *unwritten* data, but not
streams with *unread* data.  So this testcase is still valid and
should work.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

Attachment: pgps53eyLIgyR.pgp
Description: PGP signature

Reply via email to