Is it possible to detect loss of power on a laptop/desktop without an UPS?  Obviously a computer without an UPS will shutdown at least almost immediately after being unplugged/having its battery pulled. However, I thought maybe that the kernel could notice the loss of power before the capacitors/inductors drained completely and have a very short chance to do something.I know if I have a properly configured UPS, powerd will send SIGPWR to init so an organized shutdown can happen. I'm interested in the case where I don't have an UPS attached, so obviously there would be at best a very short window in which to shutdown. All I'd really want is to write a single timestamp (or failing that, any string) to a logfile so I could know about the power failure.I somehow doubt that SIGPWR will actually be helpful in this case, since I doubt the kernel is going to send it to every single process, it was just the first thing that came to mind. Perhaps there would be some control line or file I could poll on that the kernel would update? Or perhaps I'm just screwed, which to be honest is kind of what I expect.
Detect power loss
power management;signals;ups
The time window even for an external 680uFx400V capacitor battery is very low for an average 100W desktop PC - just a half a second or so. With internal PSU caps it's even less. What are you really trying to achieve? Even if you will able to write a timestamp to a log file, you still need sync() cycle to happen or to do manual sync() call, and if you're unlucky and your machine does busy work dumping other queued disk buffers - you're out.If you're need to detect a power failure almost reliably, then I suggest you to touch a flag file at boot, remove it during normal shutdown. The existence of this file will tell you that machine was not shutdown cleanly (but it will not save you from other failures, mostly software ones like kernel panics).