Reading Gilles' answer,

SIGHUP is about the same as SIGTERM in terms of harshness, but it has a specific role because it's automatically sent to applications running in a terminal when the user disconnects from that terminal (etymologically, because the user was connecting via a telephone line and the modem hung up). SIGHUP is often involuntary, unlike SIGTERM which has to be sent explicitly, so applications should try to save their state on a SIGHUP.

Does "explicitly" in "SIGTERM which has to be sent explicitly" mean that SIGTERM must be sent initially by a process (instead of the kernel) via the process calling kill()?

I was wondering if SIGKILL must be explicitly sent to a specified process? Can kernel implicitly send any of SIGKILL and SIGTERM to a process?

When an OS is shut down, does the kernel send some signal(s) to running processes to terminate them? What signal(s) is it and does the kernel send it implicitly?

Thanks.

  • Of course kernel will send sigkill to processes. Like when you call reboot () – 神秘德里克 Dec 6 at 12:54
  • 1
    @神秘德里克 AFAICT reboot() doesn’t send SIGKILL. – Stephen Kitt Dec 6 at 13:14

As far as I can tell, the Linux kernel doesn’t send SIGTERM on its own to user processes. (SIGTERM is used internally with kernel threads.)

The kernel does send SIGKILL to user processes of its own accord, in a number of circumstances. For example, the OOM killer kills its target with SIGKILL; some kernel oops result in a SIGKILL; various memory failures can result in SIGKILLs.

When the operating system shuts down, processes are shut down using SIGTERM and SIGKILL, but those signals don’t come from the kernel (or not directly — calling kill() with a pid of 0 or a negative pid will result in the kernel sending the signal to a number of processes). They come from a service manager terminating its services and from various last-ditch-kill-everything application-mode programs that are part of the system management mechanism: e.g. the killprocs van Smoorenburg rc script, the killprocs OpenRC script, and the systemd-shutdown program.

When the kernel shuts down, or reboots, it doesn’t care about processes and doesn’t kill them (see reboot() for details; I’m considering that the variant which uses an external command to shut down isn’t the kernel).

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.