six*_*ude 25 unix bash kill manpages
我的手册页没有记录两者之间的区别
kill <pid>
Run Code Online (Sandbox Code Playgroud)
和
kill -9 <pid>
Run Code Online (Sandbox Code Playgroud)
既然这些做了不同的事情,为什么 -9 没有记录在kill联机帮助页中? 我想也许这是一个特定于 shell 的东西,所以我也查看了 bash 手册页,但没有运气。
额外问题: -9 有什么作用?
Mar*_*Pim 40
kill只是向给定进程发送信号。该-9告诉它哪些信号发送。
不同的数字对应不同的公共信号。SIGINT,例如,是 2,所以要发送一个进程SIGINT信号发出命令
$ kill -2 <pid>
Run Code Online (Sandbox Code Playgroud)
kill 的默认信号是 TERM。
联机帮助页还提供了您可以发送的信号表。根据这个表,TERMis 15,所以这些都是等价的:
kill <pid>
kill -15 <pid>
kill -TERM <pid>
Run Code Online (Sandbox Code Playgroud)
注意 9 是KILL信号。
Name Number Action
-----------------------
ALRM 14 exit
HUP 1 exit
INT 2 exit
KILL 9 exit this signal may not be blocked
PIPE 13 exit
POLL exit
PROF exit
TERM 15 exit [Default]
USR1 exit
USR2 exit
VTALRM exit
STKFLT exit may not be implemented
PWR ignore may exit on some systems
WINCH ignore
CHLD ignore
URG ignore
TSTP stop may interact with the shell
TTIN stop may interact with the shell
TTOU stop may interact with the shell
STOP stop this signal may not be blocked
CONT restart continue if stopped, otherwise ignore
ABRT 6 core
FPE 8 core
ILL 4 core
QUIT 3 core
SEGV 11 core
TRAP 5 core
SYS core may not be implemented
EMT core may not be implemented
BUS core core dump may fail
XCPU core core dump may fail
XFSZ core core dump may fail
Run Code Online (Sandbox Code Playgroud)
默认信号是 TERM,它允许被杀死的程序在退出之前捕获它并进行一些清理。如果程序是这样编写的,它也可以忽略它。
指定 -9 或 KILL 作为信号不允许程序捕获它、进行任何清理或忽略它。它应该只用作最后的手段。
要在 Bash 中查看数字和信号名称列表,请使用kill -l(字母 ell)。