Hello all,
I thought this was fairly simple (and it probably is). But I am not
able to figure out how I can fork() off, say, five child processes, and
wait for all of them to terminate.
Is the code below on the right track? Is it as simple as
"wait for [EMAIL PROTECTED]"? I think this will let me wait N times,
where N is the number of children launched. Am I right? TIA.
Is there a simpler "wait-for-all-descendants" primitive?
If some of my children are hanging, can I detect that,
and take action to terminate them?
> my @children; # Keep track of my children's PID's.
> for (1..5) {
> my $pid = fork;
> if ($pid) {
> # I am in the parent.
> push @children, $pid;
> } elsif (defined $pid) {
> &do_some_child_stuff($_);
> } else {
> warn "Warning: fork() #$_ failed";
> }
> } # for (1..5)
>
> if (@children) {
> # I am in the parent.
> if ($wait_order eq 'FIFO') {
> waitpid $_ for @children;
> print "I waited for my children in FIFO order.\n";
> } else {
> wait for [EMAIL PROTECTED];
> print "I waited for my children without imposing an order.\n";
> }
> &do_some_adult_stuff;
> } # if (@children)
peace, || No Coke at University of Michigan:
--{kr.pA} || http://tinyurl.com/cbdal
--
How do you spell "unwritten rule"?
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm