首页·终端命令

kill

进程与系统

用法

kill [-SIGNAL] <pid>

给指定 PID 发信号让进程退出;默认的 TERM 会留出清理时间,而 `-9` 无法被拦截,打开的文件和锁文件会留在原地。

常用选项

选项含义
-15 / -TERMThe default: ask the process to shut down so it can clean up.
-9 / -KILLCannot be caught or ignored. The process dies immediately with no cleanup.
-1 / -HUPTraditionally means "reload your configuration" for daemons.
-0Send nothing; just test whether the PID exists and you may signal it.
-lList the signal names and numbers on this system.

示例

kill 1234

Politely ask PID 1234 to exit.

kill -9 1234

Force it out after the polite attempt did nothing.

kill -HUP $(pgrep -o nginx)

Tell the nginx master process to reload its config.

看什么在跑、什么在吃机器。先弄清是什么,再决定杀不杀。

怎么看

  • 方括号 [ ] 表示这部分可以不写。
  • 省略号 … 表示可以写多个。
  • 选项区分大小写——有些命令里 -r 和 -R 不是一回事。

常见问题

Q. kill 是做什么的?

给指定 PID 发信号让进程退出;默认的 TERM 会留出清理时间,而 `-9` 无法被拦截,打开的文件和锁文件会留在原地。

Q. 怎么写?

kill [-SIGNAL] <pid> —— 方括号表示可以省略的部分。

Q. 值得记的选项有几个?

这里列了 5 个,完整列表在 man kill。这条命令属于进程与系统。

相关命令

man 手册: man kill