How do I catch a KILL or HUP or User Abort signal?

孤者浪人 提交于 2019-12-05 02:11:01

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.

Perl:

@SIG{qw( INT TERM HUP )} = \&safe_exit;

SIGKILL cannot be caught. It is not sent to the process.

%SIG is documented in perlvar. See also perlipc

For the perl version, see perldoc -q signal -- basically, set $SIG{signal} to a sub reference.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!