Dragonchild is correct about how you setup signal handlers.

Better then using the UNIX command-line kill command, is using perl's built-in kill function. For example to send the INT signal to the process ID in the $pid variable you could use:

kill INT => $pid; # which is the same as kill 'INT', $pid;

Note that people often do something like:

$SIG{INT} = sub { # code executed on 'INT' signal here }; # <-- that semicolon isn't optional

...using an anonymous subroutine instead of a named one.

Often if one just wants to handle a signal differently for a small section of code one can take advantage of local to temperarily set a signal handler up. For example:

{ my $stop = 0; local $SIG{INT} = sub { $stop++ }; while (!$stop) { # the loop continues until it's left with an explict # last, or until the process recieves SIGINT. } } # our old SIGINT handle is restored here, because we # left the old block.

(Though you can of course manually store the current signal handler, set a new one, and reset the signal handler when you are done if you want.)


In reply to Re: signal handling by wog
in thread signal handling by Seshouan

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.