Perl - Signal Handling
How can we handle signal?
Take a look at Sys::SigAction
$SIG{"INT"} = "my_sigint_catcher"; // Register the name of the function that will handle
// the interrupt signal when the program receive an
// interrupt signal
sub catch_zap {
my $signame = shift;
die "Somebody sent me a SIG $signame";
}
SIG{INT} = \&catch_zap;
sub precious {
local $SIG{INT} = 'IGNORE';
&more_functions;
}
sub more_functions {
# interrupts are still ignored for now
}
{
local $SIG{HUP} = 'IGNORE'; // does not kill itself
kill HUP => -$$; // kill all process in current process group
// kill('HUP', -$$)
}
unless (kill 0 => $kid_pid) {
// check $kid_pid is alive or has change UID
warn "Something wicked happened to $kid_pid";
}
page revision: 2, last edited: 11 Apr 2016 00:58