Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Signals and END block

by Marcello (Hermit)
on Aug 04, 2004 at 09:34 UTC ( [id://379945]=note: print w/replies, xml ) Need Help??


in reply to Re: Signals and END block
in thread Signals and END block

The halt script indeeds clarifies this question. First a TERM signal and after 5 seconds a KILL signal.

  • Why not having the cleanup code in the signal handler itself, though?

    It also needs to execute when the programs ends normally, so the END block is probably the best place.

  • Why don't you try to detect and delete the stale database record at startup if possible?

    Since I store the PID value of the process in a database, this PID might be re-used by the operating system when deleting the record at startup.
    Thanks for your helpful input.
  • Replies are listed 'Best First'.
    Re^3: Signals and END block
    by bluto (Curate) on Aug 04, 2004 at 16:00 UTC
      Since I store the PID value of the process in a database, this PID might be re-used by the operating system when deleting the record at startup.

      There is no way to handle 100% of the termination cases at the time of termination no matter what you do (e.g. your machine suddenly loses power and the UPS fails), so you must have code that detects stale records at some future point in time. There are several ways of doing this. The canonical way to verify a pid is to record it in a lock file that the process keeps locked while it is running. When you verify the pid, if you can lock the file, the process has obviously died. Another more generic way could be to write a separate "checkpoint" record that you remove in your END block. If you start up and the checkpoint record exists, you remove the stale PID record the that checkpoint record points to as well as the checkpoint record.

    Re^3: Signals and END block
    by etcshadow (Priest) on Aug 04, 2004 at 15:20 UTC
      Since I store the PID value of the process in a database, this PID might be re-used by the operating system when deleting the record at startup.
      Right, but you can check to see if that pid exists, and if so, what process actually holds that pid. If the process that holds the pid is not the same as the process you are tracking, then you can assume that your process was killed abruptly and that you can delete the pid-record and start.
      ------------ :Wq Not an editor command: Wq

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Node Status?
    node history
    Node Type: note [id://379945]
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others learning in the Monastery: (3)
    As of 2024-04-25 10:08 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found