【发布时间】:2011-06-13 17:33:27
【问题描述】:
如果没有明确设置 Perl 程序的 %SIG 条目,哪些信号会导致停止运行?
【问题讨论】:
-
问题是跨平台的,我下面的答案是特定于平台的(因为这是我可以轻松访问的)。似乎答案与 SIG_DFL 的定义有很大关系。例外似乎是 FPE,它看起来默认设置为 SIG_IGN。
如果没有明确设置 Perl 程序的 %SIG 条目,哪些信号会导致停止运行?
【问题讨论】:
答案取决于平台。要查看您自己系统上每个信号的默认行为,请下载Signals::XSIG 模块(您不需要安装它)并运行程序spike/analyze_default_signal_behavior.pl(不带参数)。或者直接从here 下载并运行脚本。
请注意,即使您安装了%SIG 处理程序,您的程序也无法捕获某些信号。这也取决于系统,但通常至少包括SIGKILL 和SIGSTOP。
【讨论】:
谈论那些不会停止你的程序的事情会更容易。在我的机器 (RHEL) 上,除了 FPE(浮点异常)、CHLD(子状态更改)、CONT(继续进程)、URG(套接字上的紧急情况)和 WINCH(窗口大小更改)之外的所有内容都会导致 Perl 程序停止正在执行。
其中四个信号不会导致程序退出,而是暂时导致程序停止执行:STOP(停止,不可阻塞)、TSTP(终端停止)、TTIN(从tty读取后台)、TTOU(后台写到 tty)。如果收到 CONT,程序将重新开始运行。
【讨论】:
来自 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
【讨论】: