1

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.

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

1 Answer 1

5

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: that’s how the kernel asks a kernel thread to stop.)

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; ignore the LINUX_REBOOT_CMD_RESTART2 variant of the system call, you can’t use the command argument to handle processes).

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .