First off, you should try writing the program and ignore signals since Perl handles interrupt signals quite gracefully by default. If that does not work, you should add signal trapping as required.

"How do I trap control characters/signals?" in perlfaq8 shows the most basic way of traping signals by using the %SIG hash. This is a very basic approach but might suffice for your purpose.

On a Unix system, I would do this:

$SIG{HUP} = \&reload; $SIG{TERM} = \&terminate; sub reload { # do whatever needs doing to restart } sub terminate { # terminate database connection, etc... }

If you need to delay signals in some portions of your code though, you might want to take a look at the sig* routines in POSIX module.

use POSIX qw(:signal_h); # do something # <criticalSection> my $sigSet = POSIX::SigSet->new; my $blockSet = POSIX::SigSet->new(SIGTERM, SIGHUP); die "Error restoring signal set: $!" unless sigprocmask(SIG_BLOCK, $blockSet, $sigSet) # do critical (uninterruptable) stuff die "Error restoring original signal set: $!" unless sigprocmask(SIG_SETMASK, $sigSet) # </criticalSection> # do other stuff here

I don't see why this wouldn't work on Windows.


In reply to Re: Signal Trapping..help please by holo
in thread Signal Trapping..help please by Grygonos

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.