kage-yojimbo has asked for the wisdom of the Perl Monks concerning the following question:
# extract IP address and site name from input file foreach my $line (<>) { # grab the data of interest - that would be an IP address @words = match_array ( $line, '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}' +, '\s+' ); if ($#words) { # grab the ip address and name from each line of input $ip = $words[0]; $name = "@words[1..$#words]"; # push that information onto the test stack push @test_stack, $ip; push @test_stack, $name; } } # foreach my $line (<>) # do a traceroute if ($traceroute_flag) { $header = "\nPerforming traceroute to "; $command = "tracert"; } # do a ping if ($ping_flag) { $header = "\nSending test ping to "; $command = "ping -l 1200 "; } # fork to do everything at once # go through the list of ip addresses and fork to do commands on each +address for (my $i = 0; $i < $#test_stack; $i+=2) { my $ip = $test_stack[$i]; my $name = $test_stack[$i+1]; my $pid; # process id of spawned process # print ("forked for ip = $ip, name = $name \n"); next if $pid = fork; # parent goes to next command pair die "fork failed: $!" unless defined $pid; system ( " $command $ip > logs\\$ip.log " ); exit; # end the child process } #print "All forked processes dispatched !\n"; #print "Wait for all forked processes to finish\n"; 1 while wait() > 0; #print "Wait a little longer for processes to finish\n"; sleep 5;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: wait problem for WIN32 perl
by thundergnat (Deacon) on May 19, 2005 at 17:33 UTC | |
by kage-yojimbo (Initiate) on May 20, 2005 at 15:20 UTC | |
by BrowserUk (Patriarch) on May 20, 2005 at 15:43 UTC | |
by merlyn (Sage) on May 20, 2005 at 17:55 UTC | |
by BrowserUk (Patriarch) on May 20, 2005 at 18:31 UTC |