Reputation: 1716
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 ?
Upvotes: 0
Views: 299
Reputation: 28902
As per the man page, when shutdown is run, all processes are sent a SIGTERM. So if you write your own signal handler for SIGTERM, you should not need to include any other scripts.
Upvotes: 3