in reply to wait_all_children for Proc::Fork?

I would imagine collecting all the child PIDs in the parent process first and then waitpid for them in a loop:
parent { push @child_pids, $_[0] }

and then after the last run_fork:
# wait to reap all children for my $pid (@child_pids) { waitpid $pid, 0; }

Replies are listed 'Best First'.
Re^2: wait_all_children for Proc::Fork?
by Bloodnok (Vicar) on Jun 10, 2009 at 09:15 UTC
    At the risk of identifying a problem without proposing a solution, the above would work until one of the children hangs - causing the parent to hang.

    A user level that continues to overstate my experience :-))
      Right. Fix the real problem in the child, or just add a timeout:
      # wait to reap all children for my $pid (@child_pids) { local $SIG{__DIE__}; local $@ = ""; eval { local $SIG{ALRM} = sub { die("alarm\n") }; alarm(3600); # potentially long operation waitpid $pid, 0; alarm(0); 1; } or do { die($@) unless $@ eq "alarm\n"; # timed out warn("Waited too long for child $pid. Skipping it.\n"); } }