Created
February 9, 2016 16:32
-
-
Save piersy/c78a587568c1ba27c456 to your computer and use it in GitHub Desktop.
Asynchronous subprocess handling in bash
This file contains 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
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