How to identify shutdown event in linux
In my Ubuntu application, I wanted to perform certain finalization for my application before the system is being shutdown. For that, I need to identify the shutdown event in my application.
From what I have read online, there are mainly two major solutions, that are being suggested.
using the 'PrepareForShutdown' dbus signal.
trapping the SIGTERM signal that is send to the running applications prior to shutdown.
However, I have tried both the ways and they don't seem to work for me. The handler that I m registering for 'PrepareForShutdown' never gets invoked.
For method 2, I have observed that my application does not receive SIGTERM signal, instead it receives some other signal a moment before being terminated using SIGKILL.
Can someone help me out, what should I be using to identify the shutdown correctly? I do not intend to read it from certain OS files, please provide an event based solution.
|