How to wait in bash for several subprocesses to finish and return exit code !=0 when any subprocess ends with code !=0?

后端 未结 30 2325
悲哀的现实
悲哀的现实 2020-11-22 03:50

How to wait in a bash script for several subprocesses spawned from that script to finish and return exit code !=0 when any of the subprocesses ends with code !=0 ?

S

30条回答
  •  有刺的猬
    2020-11-22 04:11

    If you have GNU Parallel installed you can do:

    # If doCalculations is a function
    export -f doCalculations
    seq 0 9 | parallel doCalculations {}
    

    GNU Parallel will give you exit code:

    • 0 - All jobs ran without error.

    • 1-253 - Some of the jobs failed. The exit status gives the number of failed jobs

    • 254 - More than 253 jobs failed.

    • 255 - Other error.

    Watch the intro videos to learn more: http://pi.dk/1

提交回复
热议问题