Created
October 17, 2014 16:29
-
-
Save jainvishal/847752f04d3a6c8239cc to your computer and use it in GitHub Desktop.
Tips
This file contains hidden or 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
| # Signal Hanlder | |
| Handle_Exit_Safely() | |
| { | |
| rm -f $lockfile | |
| exit | |
| } | |
| # Main body | |
| if [ ! -e $lockfile ]; then | |
| # Arm the handler | |
| trap Handle_Exit_Safely INT TERM | |
| trap "rm -f $lockfile; exit" EXIT | |
| touch $lockfile | |
| # critical-section of the code, do something here | |
| rm $lockfile | |
| # Disarm the handler | |
| trap - INT TERM EXIT | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment