问题
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