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

Re^2: print on reboot or process shutdown

by marto9 (Beadle)
on Jul 29, 2008 at 21:18 UTC ( [id://700926]=note: print w/replies, xml ) Need Help??


in reply to Re: print on reboot or process shutdown
in thread print on reboot or process shutdown

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.

Replies are listed 'Best First'.
Re^3: print on reboot or process shutdown
by gaal (Parson) on Jul 29, 2008 at 21:31 UTC
    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.

Re^3: print on reboot or process shutdown
by psini (Deacon) on Jul 29, 2008 at 21:30 UTC

    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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-23 06:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found