Skip to content

Instantly share code, notes, and snippets.

@jainvishal
Created October 17, 2014 16:29
Show Gist options
  • Select an option

  • Save jainvishal/847752f04d3a6c8239cc to your computer and use it in GitHub Desktop.

Select an option

Save jainvishal/847752f04d3a6c8239cc to your computer and use it in GitHub Desktop.
Tips
# 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