I am using the following code to run a series of processes at the same time. I have an 8 processer server, thus I limit the number of runs at one moment to 5, then start processes. The following code is fine, but it waits for all the 5 processes to finish in order to start the next 5. It would have been better if I start with 5 and replace the one which is finished immediately with a new one, thus have 5 processes running at same time always. Any ideas?
Thanks
Adam
DATELOOP:
while ( ($currentdate <= $enddate) && ($item < 5) )
{
$item++;
pipe *{$item},RETHAND;
unless ($pid = fork()) {
print "$command\n";
system($command);
print RETHAND "Completed $currentdate\n";
exit();
}
$currentdate = nextdate($currentdate);
}
foreach $item2 (@waitlist) {
$response = <$item2>; # received from $item
print "$response\n";
$item--;
}
if ($currentdate <= $enddate) {goto DATELOOP;}