Version française
Home     About     Download     Resources     Contact us    
Browse thread
printf and fork question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Gerd Stolpmann <gerd@g...>
Subject: Re: [Caml-list] printf and fork question
Am Montag, den 07.03.2005, 14:44 +0100 schrieb Michael:
> Hi,
> 
> I don't understand why this:
> 
> open Unix;;
> let _ = 
> 	Printf.printf "Hi! %d\n" (getpid());
> 	match fork() with
> 	| 0 -> if fork() <> 0 then exit 0;
> 	       ()
> 	| id -> ignore (waitpid [] id)
> 
> prints out that:
> Hi! 12215
> Hi! 12215
> Hi! 12215

You have three copies of the stdout buffer. Call "flush stdout" after
printf.

Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
------------------------------------------------------------