On Fri, 2015-12-04 at 09:30 -0800, Rick Stevens wrote:
To make sure the lockfile gets deleted, you must create a function
that deletes the lockfile, and specify that function in a trap call
to trap SIGINT, SIGTERM, etc. That way it cleans up after itself if
you abort it.
For Shell scripts you can also trap on EXIT (a pseudo-signal that
triggers when the Shell is about to return normally).
However this isn't enough if the system crashes. For completeness you
also need code to clean up expired lock files e.g. on system reboot.
poc