Loading ...
Sorry, an error occurred while loading the content.

Setting SIG{CHLD} to IGNORE in fork() changes result of system() call

Expand Messages
  • Kelly Jones
    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
    Message 1 of 1 , May 17, 2010
      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 $? >

      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

      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.

      We're just a Bunch Of Regular Guys, a collective group that's trying
      to understand and assimilate technology. We feel that resistance to
      new ideas and technology is unwise and ultimately futile.
    Your message has been successfully submitted and would be delivered to recipients shortly.