killall
行程與系統
用法
killall [-SIGNAL] <name>按名字而不是 PID 一次結束多個行程;名字必須和執行檔完全一致,所以 `killall chrome` 抓不到叫 "Google Chrome" 的行程。
常用選項
| 選項 | 含義 |
|---|---|
| -9 | Force, with no chance for the process to clean up. |
| -i | Ask for confirmation before each kill (Linux). |
| -u <user> | Only the processes of that user with this name. |
| -e | Require an exact match for names longer than 15 characters (Linux). |
| -w | Wait until the processes are really gone (Linux). |
| -m <pattern> | Treat the argument as a regular expression (macOS/BSD). |
範例
killall nodeStop every process whose executable is named node.
killall -9 DockForce-restart the macOS Dock, which relaunches itself.
看什麼在跑、什麼在吃機器。先弄清是什麼,再決定殺不殺。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. killall 是做什麼的?
按名字而不是 PID 一次結束多個行程;名字必須和執行檔完全一致,所以 `killall chrome` 抓不到叫 "Google Chrome" 的行程。
Q. 怎麼寫?
killall [-SIGNAL] <name> —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 6 個,完整列表在 man killall。這條命令屬於行程與系統。
相關命令
man 手冊: man killall