Silas has asked for the wisdom of the Perl Monks concerning the following question:
for ($i = 1; $i <= 3; $i++) {
if ($pid=fork) {
$return = &my_function($i);
print "Returned: $return\n";
exit;
}
}
print "All done.\n";
The problem is that the "All done" is printed firstly, and then the "Returned:" lines are printed. The output looks like this:
All done. Returned: sub-process 3 is done. Returned: sub-process 2 is done. Returned: sub-process 1 is done.What's the best way to wait for all those subprocesses to finish (don't worry, I have timeout trapping in &my_function) before proceeding with the rest of the code?
I've read the docs on perlipc and fork but can't quite find what I want. Thanks in advance for your help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Forking and waiting
by lhoward (Vicar) on May 29, 2000 at 07:57 UTC | |
by Silas (Novice) on May 29, 2000 at 07:58 UTC | |
by slayven (Pilgrim) on May 29, 2000 at 19:16 UTC | |
by strictvars (Sexton) on Apr 15, 2005 at 19:20 UTC | |
by takshaka (Friar) on May 29, 2000 at 22:44 UTC | |
by slayven (Pilgrim) on May 29, 2000 at 23:27 UTC | |
by Silas (Novice) on May 30, 2000 at 21:53 UTC | |
by takshaka (Friar) on May 30, 2000 at 23:27 UTC | |
|
Sometimes there is text held in the output buffer
by Corion (Patriarch) on May 29, 2000 at 13:55 UTC |