Tell me what happens when you run this:
open(MFOUT,">mfout.txt");
my @commands= (
'echo "Hello1"',
'echo "Hello2"',
'echo "Hello3"',
'echo "Hello4"',
'echo "Hello5"',
);
my %running = ();
my $max_jobs = 2;
my $job_count = 0;
while ( @commands || %running )
{
if ( @commands && ($job_count < $max_jobs))
{
my $command = shift(@commands);
my $pid;
if ($pid = fork)
{
print "Parent Pid $$\n";
$running{$pid} = $command;
++$job_count;
}
else
{
die "cannot fork: $!" unless defined $pid;
print "Child Pid $$ $command\n";
print MFOUT `$command`;
my $rc = system $command;
exit($rc>>8);
}
}
else
{
my $child_pid = wait();
if (! exists $running{$child_pid})
{
warn "Reaped unkown process id $child_pid!!";
}
elsif ($?)
{
my $rc = $? >> 8;
warn "Process '$child_pid:$running{$child_pid}' errored with retu
+rn code '$
rc'";
}
print "command '$running{$child_pid}' completed\n";
delete $running{$child_pid};
--$job_count;
}
}
print "The end!\n";
print MFOUT "The end!\n";
____________________
Jeremy
I didn't believe in evil until I dated it. |