kill
进程与系统
用法
kill [-SIGNAL] <pid>给指定 PID 发信号让进程退出;默认的 TERM 会留出清理时间,而 `-9` 无法被拦截,打开的文件和锁文件会留在原地。
常用选项
| 选项 | 含义 |
|---|---|
| -15 / -TERM | The default: ask the process to shut down so it can clean up. |
| -9 / -KILL | Cannot be caught or ignored. The process dies immediately with no cleanup. |
| -1 / -HUP | Traditionally means "reload your configuration" for daemons. |
| -0 | Send nothing; just test whether the PID exists and you may signal it. |
| -l | List the signal names and numbers on this system. |
示例
kill 1234Politely ask PID 1234 to exit.
kill -9 1234Force 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