You can either either ignore a signal instance or handle it, but not both. Only future signals will be affected by your $SIG{TERM} = "IGNORE".

use Time::HiRes qw( sleep ); # Optional. print("Process Id = $$\n"); print("Start time = " . localtime() . "\n"); my $term_sig; local $SIG{TERM} = sub { $SIG{TERM} = "IGNORE"; $term_sig = 1; }; # Sleep for 20 seconds. Ignore interruptions. my $sleep_til = time() + 20; for (;;) { my $sleep_len = $sleep_til - time(); last if $sleep_len <= 0; sleep($sleep_len); } print("End time = " . localtime() . "\n"); if ($term_sig) { print "Received TERM signal\n" } else { print "Did not receive TERM signal\n" }

Tested:

$ 603944.pl Process Id = 65138 Start time = Fri Mar 9 01:06:18 2007 End time = Fri Mar 9 01:06:38 2007 Did not receive TERM signal $ 603944.pl Process Id = 65236 Start time = Fri Mar 9 01:07:00 2007 $ kill -s TERM 65236 End time = Fri Mar 9 01:07:20 2007 Received TERM signal

In reply to Re: Handling TERM signal by ikegami
in thread Handling TERM signal by Meridius

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.