杀死Haskell二进制文件

数学兰花

如果按Ctrl + C,则会引发异常(总是在线程0中?)。您可以根据需要捕获此错误,或者更有可能进行一些清理,然后将其重新抛出。但是通常的结果是使程序以一种或另一种方式停止。

现在假设我使用Unixkill命令。据我了解,kill基本上是向指定的进程发送一个(可配置的)Unix信号。

Haskell RTS如何对此作出反应?它记录在某处吗?可以想象发送SIGTERM与按Ctrl + C具有相同的效果,但实际上我不知道...

(当然,您可以kill用来发送与杀死信号完全无关的信号。同样,我可以想象RTS会忽略,说SIGHUPSIGPWR,但我不确定。)

本诺夫斯

在github上ghc源代码中搜索“信号”显示了installDefaultSignals函数:

void
initDefaultHandlers(void)
{
    struct sigaction action,oact;

    // install the SIGINT handler
    action.sa_handler = shutdown_handler;
    sigemptyset(&action.sa_mask);
    action.sa_flags = 0;
    if (sigaction(SIGINT, &action, &oact) != 0) {
sysErrorBelch("warning: failed to install SIGINT handler");
    }

#if defined(HAVE_SIGINTERRUPT)
    siginterrupt(SIGINT, 1);    // isn't this the default? --SDM
#endif

    // install the SIGFPE handler

    // In addition to handling SIGINT, also handle SIGFPE by ignoring it.
    // Apparently IEEE requires floating-point exceptions to be ignored by
    // default, but alpha-dec-osf3 doesn't seem to do so.

    // Commented out by SDM 2/7/2002: this causes an infinite loop on
    // some architectures when an integer division by zero occurs: we
    // don't recover from the floating point exception, and the
    // program just generates another one immediately.
#if 0
    action.sa_handler = SIG_IGN;
    sigemptyset(&action.sa_mask);
    action.sa_flags = 0;
    if (sigaction(SIGFPE, &action, &oact) != 0) {
    sysErrorBelch("warning: failed to install SIGFPE handler");
}
#endif

#ifdef alpha_HOST_ARCH
    ieee_set_fp_control(0);
#endif

    // ignore SIGPIPE; see #1619
    // actually, we use an empty signal handler rather than SIG_IGN,
    // so that SIGPIPE gets reset to its default behaviour on exec.
    action.sa_handler = empty_handler;
    sigemptyset(&action.sa_mask);
    action.sa_flags = 0;
    if (sigaction(SIGPIPE, &action, &oact) != 0) {
sysErrorBelch("warning: failed to install SIGPIPE handler");
    }

    set_sigtstp_action(rtsTrue);
}

由此可见,GHC至少安装了SIGINT和SIGPIPE处理程序。我不知道源代码中是否还隐藏了其他任何信号处理程序。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章