Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect a proper shutdown

Status
Not open for further replies.

Kirsle

Programmer
Joined
Jan 21, 2006
Messages
1,179
Location
US
How can a Perl script detect when it's being "properly" shut down and execute a last bit of code when that happens? I want to make a script that should run 24/7 but have it write something to a file when it's "gracefully" shut down (i.e. ending its task with Task Manager), so that if my computer loses power suddenly or is shut down forcefully, the script will know that this happened once the computer starts back up and it can check that file that it should've written.

So how can Perl differentiate between being terminated and having the whole computer shut down forcefully?

I've tried experimenting with the DESTROY block in Perl in some of my past projects, but it always seems that this block was never really called no matter how the script died. Any pointers?
 
I would write a zero length file to a disk when the script starts, and delete it as the script exits.

If the file is there on startup, an improper shutdown was performed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top