I have this bash script: https://gist.github.com/ORESoftware/06dbb26a48d2ddf48a5a2166834e0836

when I call ql_acquire_lock in a shell, if I can call mkdir on a directory, then I acquire that lock. When I call ql_release_lock, it removes that directory, simple stuff.

Now, when ql_acquire_lock is called, it calls:

trap ql_on_trap EXIT trap ql_on_trap SIGHUP trap ql_on_trap 0

if any of those signals are received, in theory, then ql_release_lock will get called:

the problem I have is when I close a terminal window, my script does NOT capture the SIGHUP or 0 signal. When the user issues SIGINT, my trap is invoked, most certainly by EXIT. But when the user closes the terminal window (I believe that should send a SIGHUP) my script's trap does not capture the signal. Anyone know why that would be?

  • If your trap is writing a message to the dead terminal perhaps it gets another signal and dies. – meuh Mar 15 '18 at 9:10
  • If I am closing the terminal window with the close/x button what other signal would it receive before SIGHUP? I also heard that trap x 0 was sort of a catchall, and would therefore always be invoked. – Alexander Mills Mar 15 '18 at 14:48
  • 1
    I was thinking of what might happen if the sighup trap starts to run, then gets killed by something like sigpipe if it writes to some file descriptor towards another process that also dies with the window. trap 0 and trap exit are the same. Your ql_on_trap will be called by the sighup and again by the exit. Is that ok? Try adding set -x to the script and redirecting stderr to a file so you can see what might be happening. – meuh Mar 15 '18 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.