On May 17, 12:35 pm, kelly.terry.jo...@gmail.com (Kelly Jones) wrote: > These 3 lines of code: > > if (fork()) {sleep 10; exit(0);} > $SIG{'CHLD'} = 'IGNORE'; > exit(system("/usr/lib/nagios/plugins/check_ping -H google.com -w > 500,20% -c 1000,40% 1> /tmp/stdout.txt 2> /tmp/stderr.txt; echo $? > > /tmp/res.txt")); > > return "PING WARNING - Packet loss = 0%, RTA = 62.08 > ms|rta=62.077999ms;500.000000;1000.000000;0.000000 pl=0%;20;40;0" into > /tmp/stdout.txt and 256 into /tmp/res.txt (/tmp/stderr.txt remains > empty). > > If I comment out the 2nd line, it returns "PING OK - Packet loss = 0%, > RTA = 62.86 ms|rta=62.862999ms;500.000000;1000.000000;0.000000 > pl=0%;20;40;0" in /tmp/stdout.txt and 256 into /tmp/res.txt (weird?), > with /tmp/stderr.txt remaining empty. > > Why does SIG{CHLD} affect whether I get "PING WARNING" or "PING OK"? > > I ran this test several times, so this isn't google.com being slow/fast issue. > > I also realize that the first result ("PING WARNING") is odd, since > the RTA and packet loss look fine. > \
I'm not sure why your code is written this way. Why does the parent just sleep and exit? Are you perhaps trying to avoid a stalled fork parent if check_ping bogs down...? (check 'perldoc -q timeout' for better options.) Since, check_ping fails in both cases ("256 in /tmp/res.txt), did you the check_ping docs for conditions that generate errors..? Does that particular check_ping call run ok from the command line? If you're trying to avoid a zombie and don't want to simply comment out the signal ignore, why not just do a wait, since the 'system' call will block until check_ping finishes anyway: my $pid = fork(); die "fork error: $!" unless defined $pid; if ($pid) # parent { my $child = waitpid( $pid, 0 ); print "reaped: $child check_ping exit status: $?\n"; } elsif (defined $pid) # child { exec("/usr/lib/nagios/plugins/check_ping -H ... ") or warn " can't exec: $!"; } -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/