Path: utzoo!attcan!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.lang.c Subject: Re: erroneous "hello" from forked "hello world" process! Keywords: fork(), wait(), Hello World Message-ID: <1990Oct01.114141.5085@virtech.uucp> Date: 1 Oct 90 11:41:41 GMT References: Reply-To: cpcahil@virtech.UUCP (Conor P. Cahill) Organization: Virtual Technologies Inc., Sterling VA Lines: 25 In article mef@romulus.rutgers.edu (Marc Fiuczynski) writes: > >main () >{ > int pid = 1; > printf("Hello\n"); > pid=fork(); > if(pid==0){ > printf("World\n"); > } >} The problem here is that when you redirect the program to a file, the standard output is buffered. So the hello is buffered until you flush the buffer (something that is done automatically at exit) and is therefore replicated when the program forks. When the standard output is not redirected, the output will be line buffered and therefore upon seeing the \n following the hello, it is written out and hence gone before the program duplicates itself. -- Conor P. Cahill (703)430-9247 Virtual Technologies, Inc., uunet!virtech!cpcahil 46030 Manekin Plaza, Suite 160 Sterling, VA 22170