Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!mips!pacbell.com!pacbell!sactoh0!jak From: jak@sactoh0.SAC.CA.US (Jay A. Konigsberg) Newsgroups: comp.lang.c Subject: Re: erroneous "hello" from forked "hello world" process! Keywords: fork(), wait(), Hello World Message-ID: <4094@sactoh0.SAC.CA.US> Date: 2 Oct 90 01:56:44 GMT References: <8661@helios.TAMU.EDU> Organization: Sacramento Public Access Unix, Sacramento, Ca. Lines: 25 >In article mef@romulus.rutgers.edu (Marc Fiuczynski) writes: >#include > >main () >{ >printf("Hello\n"); >if(fork()==0) > printf("World\n"); >} > This is an excerise from chapter 7 in Bach's "Design on the Unix O/S". The goal isn't to know how to correct the output, but to describe why it acts the way it does. Several people have already talked about stdio being buffered and fork()'s child inheriating the file descriptors, so I won't re describe it. However, there are lots of neat excersies in this book. Perhaps more of them should be posted? -- ------------------------------------------------------------- Jay @ SAC-UNIX, Sacramento, Ca. UUCP=...pacbell!sactoh0!jak If something is worth doing, it's worth doing correctly.