It seems to me like you've got something in reverse.
fork returns undef on failure, 0 to the child, and a pid to the parent. The child, in your code, does nothing.
This is a semaphore like solution to your code:
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
}
}
}
And a regular one:
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;
}
}
}
Update: Suddenly I wondered - if you don't need to check for many at a time, why are you forking?
-nuffin
zz zZ Z Z #!perl
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.