#Bash 的 kill 命令
kill [OPTION]... PID...
功能
向进程发送信号。
类型
可执行文件(/usr/bin/kill),属于 procps。
存在同名的内置命令
kill,因此需要输入完整路径执行此命令。
参数
OPTIONS选项:-<signal>,-s <signal>,--signal <signal>- 指定要发送的信号(名称或编号);默认发送SIGTERM信号-q,--queue value- 使用sigqueue(3)而不是kill(2)来发送信号-l,--list [signal]- 列出所有信号的编号和名称;如果指定了signal,则将编号和名称进行转换-L,--table- 以表格的形式列出所有信号的编号和名称
PID- 要杀死的进程 PID
#示例
查看所有信号
$ /usr/bin/kill -l
HUP INT QUIT ILL TRAP ABRT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT
CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH POLL PWR SYS
$ /usr/bin/kill -L
1 HUP 2 INT 3 QUIT 4 ILL 5 TRAP 6 ABRT 7 BUS
8 FPE 9 KILL 10 USR1 11 SEGV 12 USR2 13 PIPE 14 ALRM
15 TERM 16 STKFLT 17 CHLD 18 CONT 19 STOP 20 TSTP 21 TTIN
22 TTOU 23 URG 24 XCPU 25 XFSZ 26 VTALRM 27 PROF 28 WINCH
29 POLL 30 PWR 31 SYS
发送信号
$ /usr/bin/killl -9 2305701 # 向 PID 为 2305701 的进程发送 SIGKILL 信号
信号的编号与名称转换
$ /usr/bin/killl -l 9
KILL
$ /usr/bin/killl -l KILL
9
#推荐阅读
#手册
KILL(1) User Commands KILL(1)
NAME
kill - send a signal to a process
SYNOPSIS
kill [options] <pid> [...]
DESCRIPTION
The default signal for kill is TERM. Use -l or -L to list available
signals. Particularly useful signals include HUP, INT, KILL, STOP,
CONT, and 0. Alternate signals may be specified in three ways: -9,
-SIGKILL or -KILL. Negative PID values may be used to choose whole
process groups; see the PGID column in ps command output. A PID of -1
is special; it indicates all processes except the kill process itself
and init.
OPTIONS
<pid> [...]
Send signal to every <pid> listed.
-<signal>
-s <signal>
--signal <signal>
Specify the signal to be sent. The signal can be specified by
using name or number. The behavior of signals is explained in
signal(7) manual page.
-q, --queue value
Use sigqueue(3) rather than kill(2) and the value argument is
used to specify an integer to be sent with the signal. If the
receiving process has installed a handler for this signal using
the SA_SIGINFO flag to sigaction(2), then it can obtain this
data via the si_value field of the siginfo_t structure.
-l, --list [signal]
List signal names. This option has optional argument, which
will convert signal number to signal name, or other way round.
-L, --table
List signal names in a nice table.
NOTES Your shell (command line interpreter) may have a built-in kill
command. You may need to run the command described here as
/bin/kill to solve the conflict.
EXAMPLES
kill -9 -1
Kill all processes you can kill.
kill -l 11
Translate number 11 into a signal name.
kill -L
List the available signal choices in a nice table.
kill 123 543 2341 3453
Send the default signal, SIGTERM, to all those processes.
SEE ALSO
kill(2), killall(1), nice(1), pkill(1), renice(1), signal(7),
sigqueue(3), skill(1)
STANDARDS
This command meets appropriate standards. The -L flag is Linux-spe‐
cific.
AUTHOR
Albert Cahalan wrote kill in 1999 to replace a bsdutils one that was
not standards compliant. The util-linux one might also work correctly.
REPORTING BUGS
Please send bug reports to [email protected]
procps-ng 2023-01-16 KILL(1)