我如何终止所有子shell进程? [英] How do I terminate all the subshell processes?
本文介绍了我如何终止所有子shell进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个bash脚本来测试服务器的负载下如何执行。
I have a bash script to test how a server performs under load.
num=1
if [ $# -gt 0 ]; then
num=$1
fi
for i in {1 .. $num}; do
(while true; do
{ time curl --silent 'http://localhost'; } 2>&1 | grep real
done) &
done
wait
当我按下Ctrl-C,主要的进程退出,但背景循环继续运行。我该如何让他们所有的出口?或者是有产卵逻辑回路的配置数量的并行执行的更好的办法?
When I hit Ctrl-C, the main process exits, but the background loops keep running. How do I make them all exit? Or is there a better way of spawning a configurable number of logic loops executing in parallel?
推荐答案
下面是一个简单的解决方案 - 只需添加下面一行在脚本的顶部:
Here's a simpler solution -- just add the following line at the top of your script:
trap "kill 0" SIGINT
杀 0
发送信号到当前进程组中的所有进程。
Killing 0
sends the signal to all processes in the current process group.
这篇关于我如何终止所有子shell进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文