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