运行并行进程,如果失败则退出所有进程 [英] Run parallel process and exit all if one fails

查看:241
本文介绍了运行并行进程,如果失败则退出所有进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码,可以并行启动make t1make t2make t3.

I have this snippet of code, to start make t1 , make t2 and make t3 in parallel.

有没有办法在一个失败的情况下杀死其余的制造过程?例如,如果make t2失败,则脚本应杀死其他两个正在运行的脚本(make t1make t3)并退出.

Is there a way to kill rest of the make processes when one fails? e.g, if make t2 fails, script should kill other 2 running (make t1 and make t3) and come out.

for ARG in '"t1" "t2" "t3"'
do
   cd ${ARG}
   make ${ARG} & pid=$!
   PID_LIST+=" $pid";
   cd -
done
trap "kill $PID_LIST" SIGINT
echo "Parallel makes have started $PID_LIST"
wait $PID_LIST

推荐答案

使用 GNU Parallel

parallel --halt now,fail=1 'cd {}; make {}' ::: t1 t2 t3

这篇关于运行并行进程,如果失败则退出所有进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆