Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.