Good Morning Monks! I am writing a WIN32 communication tester which forks so that a large number of paths can be tested. I am having problems getting the process to wait until EVERY child has finished running. ( Some of these paths have comm troubles so the tracert or ping commands will take longer to complete. )
I have tried using the WAIT, but that seems to just look for one child. Here's my code - any suggestions?
Thank you!
-- kage-yojimbo
# 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;

In reply to wait problem for WIN32 perl by kage-yojimbo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.