in reply to (slightly OT) catching SIGTERM when system goes down

try to echo inside the handler sub to see if you really don't get the signal...

It isn't a good idea in general to use a fatal-signal handler for "clean-later" marks, do the clean up for fatal signals in the handler and exit there would be my general advice...

regards,
tomte


Hlade's Law:

If you have a difficult task, give it to a lazy person --
they will find an easier way to do it.

  • Comment on Re: (slightly OT) catching SIGTERM when system goes down

Replies are listed 'Best First'.
Re: Re: (slightly OT) catching SIGTERM when system goes down
by edan (Curate) on Apr 09, 2003 at 14:16 UTC

    echo will not be seen during shutdown (where would it echo to?). Like I said, I tried it by sending the signal myself using kill, and that works. It's only during reboot that it doesn't work.

    I'm actually looking into the possibility that I realized only after I posted: I am running the program in a console and then typing reboot from another console. So won't my program get killed when the console is killed, before being killed by shutdown? If so, what signal does it get? - Gotta look into that, but now I just got pulled away on something else.

    Re: 'clean-later' marks: I thought it is best to do as little as possible inside a signal-handler because of problems with re-entrant system calls - that's why I set the global and do the clean-up work later. Am I wrong in this?

    --
    3dan

      echo will not be seen during shutdown

      I meant your echo system-call with redirection to the file.

      I'm actually looking into the possibility that I realized only after I posted: I am running the program in a console and then

      But still as a daemon? The console-shell being shut-down wont kill a daemonized prozess... (daemon, is that the correct spelling?)

      Re: 'clean-later' marks: I thought it is best to do as little as possible inside a signal-handler because of problems with re-entrant system calls - that's why I set the global and do the clean-up work later. Am I wrong in this?

      I guess you may be right under 'normal' circumstances, but a fatal signal like kill is, well, fatal; you either react or you don't, just setting a mark and going ahead won't work in the generell case, because your programm will likely be killed/terminated (as signaled) before it can check this mark (compare robartes post).

      regards,
      tomte


      Hlade's Law:

      If you have a difficult task, give it to a lazy person --
      they will find an easier way to do it.


      Edit: fixed typo

        echo will not be seen during shutdown

        I meant your echo system-call with redirection to the file.

        Of course you did - how silly of me! I did sprinkle echos in the sig_handler, etc. - I still didn't see it on reboot. But...

        I theory the script will be run as a daemon (alternate: demon) - but during testing I'm just running it from the console. I think that's my problem - yet another example of solving bugs by just explaining the problem to someone else. But anyway, what signal will my program get in the case when its parent is a console that got killed by a reboot?

        --
        3dan
      So won't my program get killed when the console is killed, before being killed by shutdown? If so, what signal does it get?

      HUP

      --isotope
      http://www.skylab.org/~isotope/