Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: print on reboot or process shutdown

by gaal (Parson)
on Jul 29, 2008 at 21:07 UTC ( #700925=note: print w/replies, xml ) Need Help??

in reply to print on reboot or process shutdown

Read about END blocks in perlmod.

Replies are listed 'Best First'.
Re^2: print on reboot or process shutdown
by marto9 (Beadle) on Jul 29, 2008 at 21:18 UTC
    Ty. I read the doc and was able to fix it. This is the code that I place in the beginning of my script.
    END { open(THEND,">ABORTED"); close(THEND); }
    But the END block is also executed when the script finishes. And it should only be executed on reboot or process kill.
      If you only have one normal exit point to your script, have it set a flag. Check this flag in your END block, and only write to the file when it is not set.

      If you have more than one normal exit point to your script, well, refactor a bit. :-)

      PS: note that the way you're opening your file, its contents will be overwritten every time, rather than appended to. Use ">>" if you prefer the other way.

      You can use a signal handler to cacth SIGTERM

      $SIG{TERM}=sub { #do something here };

      But that cannot trap a SIGKILL so if you or your system make a kill -9, it will not be intercepted. And, no, AFAIK there is no way to intercept a SIGKILL because it should be the last resort to kill a not responding process.

      Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://700925]
[LanX]: oh thank you! :)
[Eily]: partly because I read tsj as /t͡ʃ/, don't know if that's supposed to be the case
[LanX]: Yeah I think thats Dutch spelling rule
[erix]: but we don't sneeze any K's
[choroba]: we do
[Eily]: that was a sneeze overpowering a cough
[choroba]: Czechs sneeze "Hep-cheek"
vrk adds gingerbread cookies to the platter on the sideboard.
[erix]: I'll give that a try next time
vrk takes a cookie from the platter on the sideboard.

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2017-04-24 15:44 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (442 votes). Check out past polls.