Bash & (ampersand) operator

折月煮酒 提交于 2019-11-28 19:37:07

the best I can think of is:

first & p1=$!
second & p2=$!
...

wait $p1 && wait $p2 && ..

or

wait $p1 || ( kill $p2 $p3 && exit 1 )
...

however this still enforces an order for the check of processes, so if the third fails immediately you won't notice it until the first and second finishes.

You should use && instead of &. eg:

first command && second command && third command && wait

However this will NOT run your command in parallel as every subsequent command's execution will depend on exit code 0 of the previous command.

This might work for you:

parallel -j3 --halt 2 <list_of_commands.txt

This will run 3 commands in parallel.

If any running job fails it will kill the remaining running jobs and then stop, returning the exit code of the failing job.

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