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: Olivier Andrieu <andrieu@i...>
Subject: Re: [Caml-list] printf and fork question
 > Michael [Mon, 7 Mar 2005]:
 > 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
 > 
 > 
 > with ocaml 3.08.2. Any hints?

You haven't flushed stdout : so the Hi! stays in the buffer and the
children inherit it.

-- 
   Olivier