Created
October 3, 2013 08:56
-
-
Save wildlyinaccurate/6807185 to your computer and use it in GitHub Desktop.
A simple way of checking the exit code of commands which have been run concurrently.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sleep_times=('4' '1' '2' '5' '0') | |
pids=() | |
for sleep_time in ${sleep_times[@]} | |
do | |
sleep $sleep_time & | |
pids=(${pids[@]} $!) | |
done | |
for pid in ${pids[@]} | |
do | |
wait $pid | |
echo "$pid returned $?" | |
done | |
exit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6287 returned 0 | |
6288 returned 0 | |
6289 returned 0 | |
6290 returned 0 | |
6291 returned 0 | |
0.00s user 0.01s system 0% cpu 5.008 total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you look at GNU Parallel?
Also, this example reminds me of sleep sort which is on 4chan of all places...