【问题标题】:Which (untrapped) signals will cause a Perl program to stop executing?哪些(未捕获的)信号会导致 Perl 程序停止执行?
【发布时间】:2011-06-13 17:33:27
【问题描述】:

如果没有明确设置 Perl 程序的 %SIG 条目,哪些信号会导致停止运行?

【问题讨论】:

  • 问题是跨平台的,我下面的答案是特定于平台的(因为这是我可以轻松访问的)。似乎答案与 SIG_DFL 的定义有很大关系。例外似乎是 FPE,它看起来默认设置为 SIG_IGN。

标签: perl signals


【解决方案1】:

答案取决于平台。要查看您自己系统上每个信号的默认行为,请下载Signals::XSIG 模块(您不需要安装它)并运行程序spike/analyze_default_signal_behavior.pl(不带参数)。或者直接从here 下载并运行脚本。

请注意,即使您安装了%SIG 处理程序,您的程序也无法捕获某些信号。这也取决于系统,但通常至少包括SIGKILLSIGSTOP

【讨论】:

    【解决方案2】:

    谈论那些不会停止你的程序的事情会更容易。在我的机器 (RHEL) 上,除了 FPE(浮点异常)、CHLD(子状态更改)、CONT(继续进程)、URG(套接字上的紧急情况)和 WINCH(窗口大小更改)之外的所有内容都会导致 Perl 程序停止正在执行。

    其中四个信号不会导致程序退出,而是暂时导致程序停止执行:STOP(停止,不可阻塞)、TSTP(终端停止)、TTIN(从tty读取后台)、TTOU(后台写到 tty)。如果收到 CONT,程序将重新开始运行。

    【讨论】:

      【解决方案3】:

      来自 Debian 上的 man kill

         Name     Num   Action    Description
         0          0   n/a       exit code indicates if a signal may be sent
         ALRM      14   exit
         HUP        1   exit
         INT        2   exit
         KILL       9   exit      cannot be blocked
         PIPE      13   exit
         POLL           exit
         PROF           exit
         TERM      15   exit
         USR1           exit
         USR2           exit
         VTALRM         exit
         STKFLT         exit      might not be implemented
         PWR            ignore    might exit on some systems
         WINCH          ignore
         CHLD           ignore
         URG            ignore
         TSTP           stop      might interact with the shell
         TTIN           stop      might interact with the shell
         TTOU           stop      might interact with the shell
         STOP           stop      cannot be blocked
         CONT           restart   continue if stopped, otherwise ignore
         ABRT       6   core
         FPE        8   core
         ILL        4   core
         QUIT       3   core
         SEGV      11   core
         TRAP       5   core
         SYS            core      might not be implemented
         EMT            core      might not be implemented
         BUS            core      core dump might fail
         XCPU           core      core dump might fail
         XFSZ           core      core dump might fail
      

      【讨论】:

        猜你喜欢
        • 2017-02-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-19
        • 2021-11-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多