The bash manpage on OSX (but it should be the same in other versions) has this to say about signal handling: bash 运行的非内置命令将信号处理程序设置为以下值由外壳程序从其父级继承.当作业控制不在时效果是,异步命令除了会忽略 SIGINT 和 SIGQUIT 这些继承的处理程序. Non-builtin commands run by bash have signal handlers set to the values inherited by the shell from its parent. When job control is not in effect, asynchronous commands ignore SIGINT and SIGQUIT in addition to these inherited handlers.,然后在 trap 命令下:进入外壳时忽略的信号不能被困或重置. Signals ignored upon entry to the shell cannot be trapped or reset.由于默认情况下脚本不使用作业控制,所以这就是您要讨论的情况.Since scripts don't use job control by default, this means the case you're talking about. 这篇关于无法在后台shell中捕获SIGINT信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-20 02:41