- 论坛徽章:
- 0
|
找到一篇文章讲解的不错:
https:// blog.robotshell.org/2012/necessary-details-about-signal-trap-in-shell
他也提到了楼主说的文档:
http:// mywiki.wooledge.org/SignalTrap
梳理下原因:
1、 Bash 等终端的默认行为是这样的:当按下 CTRL-C 之后,它会向当前的整个进程组发出 SIGINT 信号。而 sleep 是由当前脚本调用的,是这个脚本的子进程,默认是在同一个进程组的,所以也会收到 SIGINT 并停止执行
2、这篇文档给了我们一个更准确的说明——如果当前正有一个外部命令在前台执行,那么 trap 会等待当前命令结束以后再处理信号队列中的信号。
3、On most operating systems, ping is an example of a misbehaving process. It traps SIGINT in order to display a summary at the end, before exiting. But it fails to kill itself with SIGINT, and so the calling shell does not know that it should abort as well
这个问题挺有趣儿的,学习了。
|
|