Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] different behaviour of Unix.fork on FreeBSD and Linux
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-05-19 (10:04)
From: John Carr <jfc@M...>
Subject: Re: [Caml-list] different behaviour of Unix.fork on FreeBSD and Linux

fork duplicates the buffers holding output that has not yet been
written to a file descriptor.  If the output buffer is not empty
at the time of fork, output may be duplicated.

If output is unbuffered or line buffered the program will work
as in the BSD case.  Otherwise you need to arrange for buffered
output to be written before fork().

In C one is advised to call fflush(NULL) before fork if the child does
I/O.  If the child calls exec() immediately _exit() should be used
instead of exit() if the exec() fails.  (_exit() terminates the
process without flushing I/O buffers.)

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: