Skip to content

Instantly share code, notes, and snippets.

@elventear
Created May 7, 2013 14:38
Show Gist options
  • Save elventear/5533077 to your computer and use it in GitHub Desktop.
Save elventear/5533077 to your computer and use it in GitHub Desktop.
#bash wait on #background jobs and #subshells
#!/bin/bash
# http://jeremy.zawodny.com/blog/archives/010717.html
FAIL=0
echo "starting"
./sleeper 2 0 &
./sleeper 2 1 &
./sleeper 3 0 &
./sleeper 2 0 &
( wait 30 ) &
( wait 30 ) &
for job in `jobs -p`
do
echo $job
wait $job || let "FAIL+=1"
done
echo $FAIL
if [ "$FAIL" == "0" ];
then
echo "YAY!"
else
echo "FAIL! ($FAIL)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment