【问题标题】:Run parallel process and exit all if one fails运行并行进程并在一个失败时全部退出
【发布时间】:2017-04-03 13:39:09
【问题描述】:

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

有没有办法在一个失败时杀死其余的 make 进程?例如,如果 make t2 失败,脚本应该杀死其他 2 个正在运行的(make t1make t3)并出来。

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

【问题讨论】:

  • 你为什么使用evalfor arg in "t1" "t2" "t3"; do make "$arg" & pids+=($!); done
  • 谢谢,将按照您的建议在我的代码中更改它

标签: linux bash shell gnu


【解决方案1】:

使用 GNU 并行

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

【讨论】:

  • 谢谢 Mark,我更新了我的代码 sn-p,我必须在 make 之前 cd 到不同的目录,所以我不能将 make 合并到一行中。
  • @Krish 你总是在你的代码中切换到同一个目录......,无论如何你可以使用parallel 执行多个命令。我已经更新了代码。
  • 那是一个错字,现在请看,目录名称不同。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-04
  • 1970-01-01
  • 1970-01-01
  • 2017-03-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多