home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / perl / 5801 < prev    next >
Encoding:
Internet Message Format  |  1992-09-09  |  1.3 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!spool.mu.edu!news.cs.indiana.edu!nstn.ns.ca!dragon.acadiau.ca!merlin!peter
  2. From: peter@merlin.acadiau.ca (Peter Steele)
  3. Newsgroups: comp.lang.perl
  4. Subject: fork question
  5. Message-ID: <peter.716061574@merlin>
  6. Date: 9 Sep 92 17:59:34 GMT
  7. Sender: news@dragon.acadiau.ca
  8. Organization: Acadia University
  9. Lines: 41
  10. Nntp-Posting-Host: merlin
  11.  
  12. I have perl program that uses fork to create various child processes and
  13. I want the parent program to wait until all child processes are complete.
  14. Here's a cut down version of what I'm doing:
  15.  
  16. sub test1 {
  17.     print "test1\n";
  18.     sleep(2);
  19.     print "Done test1\n";
  20.     exit(0);
  21. }
  22.  
  23. sub test2 {
  24.     print "test2\n";
  25.     sleep(4);
  26.     print "Done test2\n";
  27.     exit(0);
  28. }
  29.  
  30. $| = 1;
  31. print "Starting...\n";
  32. fork && &test1;
  33. fork && &test2;
  34. print "Done.\n";
  35. wait; wait;
  36.  
  37. When I run this program, I'd expect the to wait calls to wait for the
  38. two child processes to complete. However, both of the calls return -1,
  39. and the parent exits before the child processes are done. Observe:
  40.  
  41. merlin% testit
  42. Starting...
  43. test1
  44. Done.
  45. test2
  46. Done test1
  47. merlin% Done test2
  48.  
  49. Why are the wait calls not waiting?
  50. --
  51. Peter Steele        Unix Services Manager            peter.steele@acadiau.ca 
  52. Acadia Univ., Wolfville, NS, Canada B0P 1X0  902-542-2201  Fax: 902-542-4364
  53.