Skip to content

Instantly share code, notes, and snippets.

@wildlyinaccurate
Created October 3, 2013 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wildlyinaccurate/6807185 to your computer and use it in GitHub Desktop.
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.
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
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
@timmow
Copy link

timmow commented Oct 3, 2013

Did you look at GNU Parallel?

Also, this example reminds me of sleep sort which is on 4chan of all places...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment