bash 如何将 SIGINT 发送到 shell 脚本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39688106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to send SIGINT to a shell script?
提问by krishnakant
I am writing a daemon with more than one process. once the first process is complete then it stops and needs mannual interrupt SIGINT(CTRL + C). After this next script is run.
我正在编写一个包含多个进程的守护进程。一旦第一个过程完成,它就会停止并需要手动中断 SIGINT(CTRL + C)。在此之后运行下一个脚本。
Process 1 ended successfully.
过程 1 成功结束。
How can add a SIGINT to proceed it further automatically ?
如何添加 SIGINT 以自动进一步处理?
The question may be trivial but could only find how can we trap a given signal in a script, but how do we add one after completion of a task ?
这个问题可能是微不足道的,但只能找到我们如何在脚本中捕获给定的信号,但是我们如何在完成任务后添加一个?
回答by ccarton
You can kill the current bash shell and all of its children with the command kill -TERM -$$
.
您可以使用命令终止当前的 bash shell 及其所有子项kill -TERM -$$
。
Edit:
编辑:
If, for example, you are launching processes like:
例如,如果您要启动以下流程:
process1 &
process2 &
process3 &
process4
To modify it so that when any process ends it kills all the others you can use:
要修改它,以便在任何进程结束时它会杀死您可以使用的所有其他进程:
( process1 ; kill -TERM -$$ ) &
( process2 ; kill -TERM -$$ ) &
( process3 ; kill -TERM -$$ ) &
process4 ; kill -TERM -$$