Home:ALL Converter>Catch shutdown console in Linux

Catch shutdown console in Linux

Ask Time:2014-04-29T00:09:23         Author:Xaltar

Json Formatter

I'd like to catch a Shutdown done by a user in a Linux terminal, such as:

sudo shutdown

I'm using the following C++ code:

myAct.sa_handler = myStructure::mySignalHandler;
sigaction(mySignal, &act, NULL);

And I'm using a script to send a mySignal signal.

However, using a script implies to modify the system's main files, and I don't want that.

Is there another solution to catch a shutdown signal via a C++ code in Linux ?

Author:Xaltar,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/23345982/catch-shutdown-console-in-linux
yy