home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / unix / programm / 5746 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  1.2 KB

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