Must SIGKILL (and SIGTERM) be explicitly sent to a specified process?

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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).


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x