- 論壇徽章:
- 0
|
找到一篇文章講解的不錯(cuò):
https:// blog.robotshell.org/2012/necessary-details-about-signal-trap-in-shell
他也提到了樓主說(shuō)的文檔:
http:// mywiki.wooledge.org/SignalTrap
梳理下原因:
1、 Bash 等終端的默認(rèn)行為是這樣的:當(dāng)按下 CTRL-C 之后,它會(huì)向當(dāng)前的整個(gè)進(jìn)程組發(fā)出 SIGINT 信號(hào)。而 sleep 是由當(dāng)前腳本調(diào)用的,是這個(gè)腳本的子進(jìn)程,默認(rèn)是在同一個(gè)進(jìn)程組的,所以也會(huì)收到 SIGINT 并停止執(zhí)行
2、這篇文檔給了我們一個(gè)更準(zhǔn)確的說(shuō)明——如果當(dāng)前正有一個(gè)外部命令在前臺(tái)執(zhí)行,那么 trap 會(huì)等待當(dāng)前命令結(jié)束以后再處理信號(hào)隊(duì)列中的信號(hào)。
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
這個(gè)問題挺有趣兒的,學(xué)習(xí)了。
|
|