Subject: Re: possible libc bug...
To: John Franklin <franklin@elfie.org>
From: Nathan J. Williams <nathanw@wasabisystems.com>
List: current-users
Date: 04/05/2004 11:07:03
John Franklin <franklin@elfie.org> writes:

> What I think should happen is the fork(2) wrapper function in libc
> should call fflush(NULL) before the fork system call.
> 
> If this isn't a bug, why is it not a bug?  That is, what is it about the
> semantics of printf() and fork() that make it the way it is?

From a standards perspective, it's because the fork() function is
described to change certain state in the child process (pid, signals,
file locks, etc) and leave everything else alone. The buffering of a
library, even a standard library like stdio, isn't mentioned in the
list; therefore, it must be identical in the parent and the child.

From a flexibility perspective, the existence of fork() and
fflush(NULL) is enough to construct a fork()-with-fflush(NULL) when
you need one, but the reverse is not true, so the former is to be
preferred.

        - Nathan