Re: fork() memory corruption... is this glibc2 or kernel?

Peter Benie (pjb1008@cam.ac.uk)
Mon, 22 Jun 1998 11:58:24 +0100


Tuomas Heino writes ("Re: fork() memory corruption... is this glibc2 or kernel? "):
> >
> > That is, glibc is correct and the bug is in your program. And
> > issuing a fflush() before the fork() is the correct fix.
> >
> Nope makes absolutely no diff... the stream which's file position is
> getting corrupted is an INPUT stream, not output; therefore fflush()
> won't have any effect on it...

You can call fflush on an input stream - it will cause a seek on the
filedescriptor associated with the stream to bring the file pointer in
line with stdio's file pointer, and the buffer associated with the
stream will be invalidated. You must flush input streams before forking;
if you don't, fclose (and therefore, exit) will have unexpected
side-effects.

Your mistake is probably that you called fflush(NULL), which only
affects output streams.

> Hmm how offtopic is this for linux-kernel?

Very. (You can use 'strace -f' to verify that the kernel is behaving
correctly.)

Peter

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu