0

Hi I need to do some process when system goes for normal or abnormal shutdown,

Please clarify my following doubts

  1. Does shell receives term signal during normal and abnormal shutdowns.
  2. Can i trap and see that signal,using trap command in shell?
  3. If so in which file i should look for this signal?
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105

1 Answers1

1

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.

Community
  • 1
  • 1
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105