home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / unix / internal / 1977 < prev    next >
Encoding:
Text File  |  1992-11-21  |  1.0 KB  |  46 lines

  1. Newsgroups: comp.unix.internals
  2. Path: sparky!uunet!cs.utexas.edu!sdd.hp.com!ux1.cso.uiuc.edu!bradley.bradley.edu!cs1!alchemy
  3. From: alchemy@cs1.bradley.edu (Mike Swiston)
  4. Subject: Re: printf() & fork() ......
  5. Message-ID: <alchemy.722398030@cs1.bradley.edu>
  6. Sender: news@bradley.bradley.edu
  7. Organization: salt of the earth in open wounds.
  8. References: <1992Nov19.133035.172@ccsun7.csie.nctu.edu.tw>
  9. Date: 22 Nov 92 02:07:10 GMT
  10. Lines: 34
  11.  
  12. In <1992Nov19.133035.172@ccsun7.csie.nctu.edu.tw> mchuang@csie.nctu.edu.tw (Ming-Chuan Huang) writes:
  13.  
  14. % #include <stdio.h>
  15.  
  16. % program 1:
  17.  
  18. % void main()
  19. % {
  20. %     printf("Hello ");
  21. %     if (fork() == 0)
  22. %         printf("world\n");
  23. % }
  24.  
  25. % result:
  26. % Hello Hello world
  27.  
  28. Under turbo cshell, I get the output:
  29. Hello world
  30. Hello  Exit 1
  31.  
  32. leading me to guess that the problem is that
  33. your output buffer isn't getting flushed the
  34. way you might expect it to be.  You can fix
  35. that like so:
  36.  
  37. #include <stdio.h>
  38.  
  39. void main()
  40. {
  41.     printf("Hello ");
  42.     fflush(stdout);
  43.     if (fork() == 0)
  44.         printf("world\n");
  45. }
  46.