Programmatically, how can I tell on LINUX that the system is rebooting?

178 Views Asked by At

There is a lot about the "procedure" LINUX undertakes when a reboot or 'imminent shutdown' is underway. I wish to understand, programmatically, and react to, that a REBOOT IS IMMINIENT.

My application gets sent TERM and HUP signals which is all good and understood. How can I tell the difference between a signal for immediate REBOOT reasons or just from another user?

CONTEXT:

If the system is 100% rebooting then my application will SAVE IT's STATE for LOAD on BOOT.

If however, a user, even "root" arbitrately kills my application then I DO NOT WISH to save the STATE.

I am using RedHat if it makes a difference.

I have attempted to research this quite extensively but so far I have not got the solution. So you know... calling STACK OVERFLOW!

Thank you in-advance.

1

There are 1 best solutions below

4
On
/run/systemd/shutdown/scheduled

This will is created if the system is using systemd.

USEC=1677685364145817
WARN_WALL=1
MODE=reboot