Posted By

nohn on 01/06/08


Tagged

Bash wait processhandling parallelization grid


Versions (?)

Execute multiple commands in background and evaluate their return codes


 / Published in: Bash
 

Execute multiple commands in background, wait for each to be finished and evaluate their return codes.

  1. #!/bin/bash
  2. /bin/false &
  3. PID1=$!
  4. /bin/true &
  5. PID2=$!
  6. wait $PID1
  7. RET1=$?
  8. wait $PID2
  9. RET2=$?
  10. if [ $RET1 == 0 ] && [ $RET2 == 0 ]; then
  11. echo succeeded
  12. exit 0
  13. else
  14. echo failed
  15. exit 1
  16. fi

Report this snippet  

You need to login to post a comment.