in reply to New Child to Wait for First Child to Die
And a regular one:my $i = 3; # how many simultaneous checks $SIG{CHLD} = sub { $i++; wait } # or something # if your signals are safe you may # want to keep a hash of PIDs and # the ip's they're associated with, # and have SIGCHLD's handler print # out the info and test result based # on $? and the return value from wait. # You should exit the child with a # status which you may check. if the # open failed exit with a nonzero value. have running foreach $remote (@iplist){ sleep until ($i); # SIGCHLD will wake us. if it wasn't sigchld we +should go back to sleep. foreach $port (@port_range){ if (fork){ $i--; # empty the reservoir } else { # ping something exit ($test_failed) ? 1 : 0; # exit with a proper value } } }
foreach my $remote (@iplist){ foreach my $port (@iprange){ if (my $pid = fork){ waitpid, $pid; print "$remote on $port test finished..."; # check $? } else { # check stuff exit ( $test_succeeded ) ? 1 : 0; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: New Child to Wait for First Child to Die
by spike_hodge (Novice) on Apr 24, 2003 at 10:54 UTC | |
by nothingmuch (Priest) on Apr 24, 2003 at 11:07 UTC |