Hi monks, I ran into a signal handler issue when writing a client server app. The client forks a process for each server to be queried and reaps the children with this signal handler upon receiving CHLD:
sub cleanup { while ((my $kpid = waitpid(-1,WNOHANG)) > 0) { delete($kids{$kpid}); $kidcount--; } }
This works fine. But lets say out of n children, m are sleeping waiting on network traffic from the server. The parent process sends USR1 signal to each one of those m children every 10 secs of uninterrupted sleep:
while ( $kidcount > 0) { my $secs = sleep 10; my $finishCount = $hostsfile->getCount - $kidcount; if ($secs == 10) { if ($outfile and $errfile) { print STDERR "Output is being logged into $outfile\n"; print STDERR "Errors are being logged into $errfile\n"; } print STDERR "\nFinished $finishCount hosts. following ($kidco +unt)hosts remaining:\n"; while ( my ($k, $v) = each %kids) { kill "USR1", $k; print STDERR "$v\n"; } print STDERR "\n"; } }
The signal handler is as follows:
sub killMyself { if ($waitcount > 6) { print STDERR "$serverName ERROR:: The host is hosed\n"; exit; } $waitcount++; }
So upon 7 USR1 signals, the kid should exit out. This works perfectly fine with perl 5.8.4 running on a 64 bit linux(redhat 4) machine. But on a 32 bit linux(redhat 4) machine with perl 5.8.0 or a solaris 8 machine running the same perl this is what happens: The first time USR1 signal is received, the child executes the handler and everything is good. On the second time, the child just terminates. What am i doing wrong? I hope the code provided above and the explanation is clear. thanks in advance -yogi

In reply to signal handler question by yogi

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.