use Proc::Queue size => 5, # => 5 parallel processes max.
qw(system_back);
use POSIX ":sys_wait_h";
use Errno qw(EINTR);
my %pid2date;
sub reap_children {
my $wait = shift;
my $pid = waitpid(-1, ($wait ? 0 : WNOHANG));
if ($pid > 0) {
print "process for date $pid2date{$pid} (pid $pid) exited with cod
+e ". ($? >> 8) . "\n";
return 1;
}
return ($! == EINTR);
}
while ($currentdate <= $enddate) {
reap_children(0);
print "$command\n";
my $pid = system_back($command);
$pid2date{$pid} = $currentdate;
$currentdate = nextdate($currentdate);
}
1 while reap_children(1);
|