pkill
プロセスとシステム
書き方
pkill [-SIGNAL] [-f] <pattern>パターンに一致するプロセスをすべて終わらせます。`-f` を付けないとコマンド名だけを見るうえ、広すぎるパターンは思わぬものまで殺すので、同じパターンで先に pgrep を試します。
よく使うオプション
| オプション | 意味 |
|---|---|
| -f | Match against the whole command line, not just the process name. |
| -u <user> | Restrict to one user. |
| -x | Require the whole name to match, not a substring. |
| -n / -o | Only the newest / only the oldest matching process. |
| -9 | Force instead of asking the process to exit. |
| -i | Case-insensitive matching. |
例
pgrep -af "node server.js" && pkill -f "node server.js"Look first, then kill exactly what you saw.
pkill -u deploy -f gunicornStop the deploy user's gunicorn workers.
何が動いていて何が資源を食っているかを見ます。止める前に何なのかを確かめるのが順番です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. pkill は何をしますか。
パターンに一致するプロセスをすべて終わらせます。`-f` を付けないとコマンド名だけを見るうえ、広すぎるパターンは思わぬものまで殺すので、同じパターンで先に pgrep を試します。
Q. どう打ちますか。
pkill [-SIGNAL] [-f] <pattern> — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは6個です。全部は man pkill にあります。このコマンドはプロセスとシステムの仲間です。
関連するコマンド
man ページ: man pkill