$maxprocs = 50; my $prox = int(scalar(@targets)/$maxprocs); my $prox_r = int(scalar(@targets)%$maxprocs); my $i = 0; if ($prox) # call the forking routine as many times as required to get most of the targets { for ( 1 .. $prox ) { &breed($maxprocs); } } if ($prox_r) # Then call the forking routine but this time only enough to catch the modulo { &breed($prox_r); } # Calculate results and print to STDOUT my $success = ( $main::avail / scalar(@targets) ) * 100; # return results as a percentage $success = sprintf('%.2f',$success); # rounded to 2 decimals print "$success\n"; ######################### sub breed ($) ######################### { my $loop = shift; for ( 1 .. $loop ) #make a bunch of kids { if ($pid=fork) { push @pids, $pid; $i ++; } elsif (defined $pid) { my $next = @targets[${i}]; &check_status($next); exit; } } foreach my $childpid (@pids) # wait for all kids to return before continuing { waitpid($childpid, 0); $main::avail += ! $?; # Increment the master counter, 0 means success, non-zero means failure } }