Skip to content

Instantly share code, notes, and snippets.

@piersy
Created February 9, 2016 16:32
Show Gist options
  • Save piersy/c78a587568c1ba27c456 to your computer and use it in GitHub Desktop.
Save piersy/c78a587568c1ba27c456 to your computer and use it in GitHub Desktop.
Asynchronous subprocess handling in bash
set -euo pipefail
exitHandler(){
echo ""
echo "script failed"
trap - SIGTERM && kill 0
}
trap exitHandler USR1 SIGINT SIGTERM EXIT
#(sleep 4; kill -USR1 $$) &
(sleep 3 && kill -USR1 $$) &
(sleep 4 ) &
wait
exitHandler(){
echo "Success"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment