in reply to Re^2: Waiting For Multiple Programs to Complete
in thread Waiting For Multiple Programs to Complete
The wait call is a form of sleep. It sleeps until SIGCHLD if there are no completed children queued up for attention. If there are, it returns the pid of the one it serviced.
Your application might look like this skeleton,
I've glossed over the design of the task hashes and the next_task() and more() functions. They will be application dependent.our %kid; sub forkus { my $task = shift; # it's a hash ref defined(my $cpid = fork) or warn $! and return; $kid{$cpid} = $_->id, return $cpid if $cpid; exec $_->cmd; exit -1; } forkus($_) for (@first_tasks); while (%kid) { my $cpid = wait; # sleep until somebody's done forkus(next_task($cpid)) if more($cpid); # suitably defined delete $kid{$cpid}; }
POE may be just what you need, but I find it somewhat difficult to work with. Lack of practice, perhaps.
After Compline,
Zaxo
|
|---|