in reply to signal handling

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.)