As noted, in a catastrophic failure (kernel panic or power outage), one should not expect a signal to be sent to a process to provide for an orderly shutdown. If the system can provide this, it would be as documented in the particular system's shutdown
, poweroff
or similar command. For instance, this Linux shutdown
manual page says that SIGTERM
is sent first, and implies that SIGKILL
will be sent later. Things may not be so orderly, of course.
These provide additional discussion on the topic:
As for which file one should try to trap the SIGTERM
, that really depends upon the application. The signal would be sent to all processes, and you cannot assume or rely upon any particular order of arrival for the signals. SIGKILL
cannot caught; when it arrives it is too late to do anything about it.