home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!spool.mu.edu!news.cs.indiana.edu!nstn.ns.ca!dragon.acadiau.ca!merlin!peter
- From: peter@merlin.acadiau.ca (Peter Steele)
- Newsgroups: comp.lang.perl
- Subject: fork question
- Message-ID: <peter.716061574@merlin>
- Date: 9 Sep 92 17:59:34 GMT
- Sender: news@dragon.acadiau.ca
- Organization: Acadia University
- Lines: 41
- Nntp-Posting-Host: merlin
-
- I have perl program that uses fork to create various child processes and
- I want the parent program to wait until all child processes are complete.
- Here's a cut down version of what I'm doing:
-
- sub test1 {
- print "test1\n";
- sleep(2);
- print "Done test1\n";
- exit(0);
- }
-
- sub test2 {
- print "test2\n";
- sleep(4);
- print "Done test2\n";
- exit(0);
- }
-
- $| = 1;
- print "Starting...\n";
- fork && &test1;
- fork && &test2;
- print "Done.\n";
- wait; wait;
-
- When I run this program, I'd expect the to wait calls to wait for the
- two child processes to complete. However, both of the calls return -1,
- and the parent exits before the child processes are done. Observe:
-
- merlin% testit
- Starting...
- test1
- Done.
- test2
- Done test1
- merlin% Done test2
-
- Why are the wait calls not waiting?
- --
- Peter Steele Unix Services Manager peter.steele@acadiau.ca
- Acadia Univ., Wolfville, NS, Canada B0P 1X0 902-542-2201 Fax: 902-542-4364
-