cdarke:

Can you point to some documentation? I did a quick search (not very thorough), and haven't found any evidence that the alarm handlers don't survive a fork. The OpenGroup alarm documentation clearly states that pending alarm signals are cleared for the child, and their fork docs state that the child process will have its alarm cleared and any pending alarm reset. So I don't see why the parent using alarm & kill wouldn't work.

I don't have my hands on a Unix box at the moment, but under windows, I get this:

301058@LOU-PC0288 /Work/METABASE $ perl forktest.pl nofork: ALARM! nofork: done... 301058@LOU-PC0288 /Work/METABASE $ perl forktest.pl a PID(2560): ALARM! PID(0): QUITTING! PID(2560): done... 301058@LOU-PC0288 /Work/METABASE $ cat forktest.pl use strict; use warnings; my $prefix="nofork"; my $PID; $SIG{INT} = sub { die "$prefix: QUITTING!\n\n"; }; $SIG{ALRM} = sub { print "$prefix: ALARM!\n\n"; kill 2,$PID if $PID; } +; alarm(5); if (@ARGV) { # with any argument we fork, o/w we don't $PID = fork; $prefix = "PID($PID)"; } # Wait long enough for alarm to trigger my $t = time; while ($t + 10 > time) { # doze } print "$prefix: done...\n\n"; alarm(0); 301058@LOU-PC0288 /Work/METABASE $

...roboticus


In reply to Re^2: SIG{ALRM} to help kill external program by roboticus
in thread SIG{ALRM} to help kill external program by locked0wn

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.