首頁·終端機命令

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