LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 01-07-2009, 09:18 AM   #1
ghataknav
LQ Newbie
 
Registered: Dec 2008
Posts: 17

Rep: Reputation: 0
Thumbs up Detect abrupt power failure by linux kernel ?


hi,

i'm using an industrial product that runs on linux. the kernel being used is 2.6.18. now, in an industrial environment, abrupt power failure is a possibility. to protect the data in the product from abrupt power failure, jffs2 filesystem is being used. i've tested it and it works like a dream.

now, my problem is that i would like to know the exact time when such a power failure occurs. is it possible for the kernel to generate some sort of log file that will be created just moments before the system gets powered off ? so that, when the power does come on, i can just read the log file and display the last time the system had shut down due to abrupt power failure. if i can get this info, then, i can also calculate the time duration for which the product was offline. is it possible to do such a thing ?

it must be noted here that, for me in this case, there is no provision to handle this problem in the hardware.

thanks in advance.
 
Old 01-07-2009, 10:40 AM   #2
TITiAN
Member
 
Registered: Mar 2008
Location: NRW, Germany
Distribution: Arch Linux, using KDE/Plasma
Posts: 392

Rep: Reputation: 49
I think there is no way to do this in the kernel, as it would mean a steady writing to a hard disk. However, it is possible to write a program (should be possible in bash; as I'm not capable of that, I will try it in C if you want and post the source code here if it works).
That program would need to be started at system start-up and get a USR-signal on system shutdown. It would do the job of steadily writing on the hard disk (like, a few bytes every minute or variable time interval).
If that program is not interrupted by the USR-signal (which would mean a system crash/power down), it can tell you how long the service has been offline.

Should I (or/and someone else...) try this?
 
Old 01-07-2009, 02:06 PM   #3
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Some distributions log periodically, for instance my Debian does so every 20 minutes. You can do it easily on your own. Then simply parse the log and find the time between last markers. Also the command similar to:
last -10 reboot
may be interesting for you (the file of interest is /var/log/wtmp). You may probably use it too.
 
Old 01-08-2009, 08:32 AM   #4
ghataknav
LQ Newbie
 
Registered: Dec 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by TITiAN View Post
I think there is no way to do this in the kernel, as it would mean a steady writing to a hard disk. However, it is possible to write a program (should be possible in bash; as I'm not capable of that, I will try it in C if you want and post the source code here if it works).
That program would need to be started at system start-up and get a USR-signal on system shutdown. It would do the job of steadily writing on the hard disk (like, a few bytes every minute or variable time interval).
If that program is not interrupted by the USR-signal (which would mean a system crash/power down), it can tell you how long the service has been offline.

Should I (or/and someone else...) try this?
thanks for your reply. honestly speaking, i had this idea of writing a C code to do this job for me; but had to abort it. actually, in this industrial product, i don't store the data in a hard disk. it is stored in a compact flash, which, in turn, has a limitation of about 1 million read/write cycles. but, you have given me a good idea about using USR SIGNAL. i'll monitor this signal in bash/C and generate a log file iff it's state changes.

thanks.
 
Old 01-08-2009, 08:38 AM   #5
ghataknav
LQ Newbie
 
Registered: Dec 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Mara View Post
Some distributions log periodically, for instance my Debian does so every 20 minutes. You can do it easily on your own. Then simply parse the log and find the time between last markers. Also the command similar to:
last -10 reboot
may be interesting for you (the file of interest is /var/log/wtmp). You may probably use it too.
thanks for your reply. i checked the "last" command and the /var/log/wtmp file. i could not fine data regarding the last reboot. but, i did find data referring to the last time a particular user had logged into the system. i guess i'll search a little more. hopefully i will get something.

thanks.
 
Old 01-09-2009, 09:21 PM   #6
map250r
Member
 
Registered: Aug 2007
Distribution: Debian Squeeze
Posts: 46

Rep: Reputation: 15
Can't the kernel get notification from a UPS about a power failure? Get a UPS, plug it into serial/usb, and set it to shut down x minutes after the power fail notification. There should be a timestamp in your log when it shuts down.

HOWEVER, I work in a factory that put UPSes on several computers. The UPSes are within electrical enclosures and failed quickly.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Power Supply failure or Motherboard failure? neilthereildeil Linux - Hardware 3 06-09-2008 04:47 PM
Suse linux 10.2 reboot issue after power failure steeles Linux - Newbie 1 03-25-2008 11:24 PM
kde not loading and now kernel panic after power failure Leoplod Linux - Hardware 2 11-10-2006 05:04 AM
set iBook to automatically power-up after power failure peachy Other *NIX 4 04-19-2006 12:44 PM
Power Failure On AC power ONLY Gateway 5300 marti35 Linux - Laptop and Netbook 1 05-22-2005 10:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 02:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration