Permalink
Browse files

Add a demo of background status.

  • Loading branch information...
Andy Chu
Andy Chu committed Mar 24, 2017
1 parent e40c9e4 commit 2632ae5aa5c22602fae41adab922b195f38bd726
Showing with 60 additions and 0 deletions.
  1. +60 −0 tests/background-status.sh
View
@@ -0,0 +1,60 @@
#!/bin/bash
#
# Usage:
# ./background-status.sh <function name>
set -o nounset
set -o pipefail
#set -o errexit # wait waill fail with this
do-some-work() {
sleep 0.2
exit $1
}
wait-pids() {
{ sleep 0.1; exit 5; } &
pid1=$!
do-some-work 6 &
pid2=$!
{ sleep 0.3; exit 7; } &
pid3=$!
do-some-work 8 &
pid4=$!
echo "Waiting for PIDs $pid1 $pid2 $pid3"
wait $pid1; echo $?
wait $pid2; echo $?
wait $pid3; echo $?
wait $pid4; echo $?
echo 'Done'
}
wait-next() {
{ sleep 0.1; exit 8; } &
pid1=$!
{ sleep 0.2; exit 9; } &
pid2=$!
{ sleep 0.3; exit 10; } &
pid3=$!
wait -n; echo $?
wait -n; echo $?
wait -n; echo $?
echo 'Done'
}
both() {
wait-pids
wait-next
}
"$@"

0 comments on commit 2632ae5

Please sign in to comment.