How do I catch a KILL or HUP or User Abort signal?
Perl:
$SIG{$_} = \&safe_exit for qw( INT TERM HUP );
SIGKILL cannot be caught. It is not sent to the process.
%SIG
is documented in perlvar. See also perlipc
PHP uses pcntl_signal
to register a signal handler, so something like this:
declare(ticks = 1);
function sig_handler($sig) {
switch($sig) {
case SIGINT:
# one branch for signal...
}
}
pcntl_signal(SIGINT, "sig_handler");
pcntl_signal(SIGTERM, "sig_handler");
pcntl_signal(SIGHUP, "sig_handler");
# Nothing for SIGKILL as it won't work and trying to will give you a warning.