Last active
July 30, 2022 05:50
-
-
Save karlsebal/d6c226ab2cb610d5f075b029c52ba2ba to your computer and use it in GitHub Desktop.
clean exit 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
#!/bin/sh | |
# How To Die Gracefully | |
cleanup() { | |
echo clean up… | |
} | |
die() { | |
echo dying gracefully | |
kill $proc | |
exit 0 | |
} | |
bg(){ | |
while :; do | |
echo bla | |
sleep 3 | |
done | |
} | |
trap cleanup EXIT | |
trap die INT | |
bg& | |
proc=$! | |
while :; do | |
echo blubb | |
sleep 13 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment