home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.programmer:5746 comp.unix.questions:14847
- Newsgroups: comp.unix.programmer,comp.unix.questions
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!spool.mu.edu!uwm.edu!linac!uchinews!machine!chinet!les
- From: les@chinet.chi.il.us (Leslie Mikesell)
- Subject: Re: Programs that fork() don't redirect output in desired way?
- Message-ID: <BzLGG9.HGI@chinet.chi.il.us>
- Organization: Chinet - Public Access UNIX
- References: <941@ncrsaud.SaudiArabia.NCR.COM>
- Date: Mon, 21 Dec 1992 05:26:32 GMT
- Lines: 17
-
- In article <941@ncrsaud.SaudiArabia.NCR.COM> kbahey@ncrsaud.SaudiArabia.NCR.COM (Khalid Bahey-elDin) writes:
-
- >Because "prog" breaks itself into three running processes, we have three
- >different processes redirecting their output to the debug file.
-
- >The problem is that the file does not contain things in chronological order.
- >What happens is that it will contain output from the parent, then output from
- >child1, then output from child2, all interspersed.
-
- >I assume this is because of system buffering for printf()s.
-
- The quick fix is to add an fflush() after each printf(), or you could
- use setvbuf() to force unbuffered or line buffered output. Fflush()
- will probably work better to keep related output together.
-
- Les Mikesell
- les@chinet.chi.il.us
-