微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

unix – 杀死一个Haskell二进制文件

如果我按Ctrl C,这将抛出异常(总是在线程0?).如果你想要 – 或者更有可能运行一些清理,然后再推翻它,你可以抓住这个.但通常的结果是使程序以某种方式停止.

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

Haskell RTS如何回应?是否记录在某个地方?我会想象发送SIGTERM将具有与Ctrl C相同的效果,但我不知道一个事实…

(当然,你可以使用kill来发送与杀戮毫无关系的信号,同样,我想象RTS会忽略SIGHUP或SIGPWR,但我不知道.)

ghc source code的github上搜索“signal”显示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,&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,&oact) != 0) {
sysErrorBelch("warning: Failed to install SIGPIPE handler");
    }

    set_sigtstp_action(rtsTrue);
}

从那里可以看出,GHC至少安装了SIGINT和SIGPIPE处理程序.我不知道是否有其他的信号处理程序隐藏在源代码中.

原文地址:https://www.jb51.cc/bash/386581.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐