Perl - Signal Handling

perl

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";
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License