Hello All! I am having problems with signals using perl 5.8.0 on win2K. Probably has to do with my inexperience with them. My humble script is acting as a ping server and uses the Net::ping module. I fork a child that starts a ping. When commanded to do so the parent will kill the child. Initally I was sending the KILL (9) to the child but this consumed memory so I switched to TERM. The problem is that the child does not always catch the signal. The problem seems to mostly exist when I am pinging an IP address that does not respond. My assumption is that the program is in the net:ping module waiting for a timeout when the signal is sent and is thus missed, but that is merely a guess. The acutal ping process is here:
sub ProcessPing { my ($Id, $IpAddr, $Command) = @_; $pingobject = Net::Ping->new(icmp,1); if ($child_pid = fork()) { #We must be the parent process return $child_pid; } elsif (defined $child_pid) { # We must be the child process $SIG{TERM} = \&int_handler ; #Since we are the child set up a #Signal handler. TERM was chosen #to try and eliminate memory cons +umption. while (1) { if ($pingobject->ping($IpAddr)) { print "Ping successfull to $IpAddr for Id $Id\n"; sleep 1; } else { print "Ping timeout occured on $IpAddr for Id $Id\n"; } } } }
The interrupt handler is:
sub int_handler { #Only called by the child. print "Caught the signal!!!!!!!!!!!!!!\n"; my $signal = shift; die "Caught the signal, Exiting!!!\n"; }
And the kill command used in another part of the program is: kill ("TERM", $child_pid_to_kill); When the signal is missed I do not see the output from the debug statement: print "Caught the signal!!!!!!!!!!!!!!\n";

Another interesting tidbit is if I switch the signal used to KILL the child dies everytime! Any ideas? Thanks


In reply to Child not Consistantly Terminating by sdl3

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.