Run parallel process and exit all if one fails

放肆的年华 提交于 2020-01-26 00:59:27

问题


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

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

回答1:


With GNU Parallel

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


来源:https://stackoverflow.com/questions/43186171/run-parallel-process-and-exit-all-if-one-fails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!