pgrep
プロセスとシステム
書き方
pgrep [-f] <pattern>pkill とまったく同じ規則で、一致するプロセスの PID だけを表示します。だから何かを殺す前の下見にちょうど向いています。
よく使うオプション
| オプション | 意味 |
|---|---|
| -f | Match the full command line, so arguments count too. |
| -a | Print the command line next to the PID (Linux). |
| -l | Print the process name next to the PID. |
| -x | Exact name match only. |
| -u <user> | Restrict to one user. |
| -c | Print how many matched instead of the PIDs. |
| -n / -o | Newest / oldest match only. |
例
pgrep -af nodeEvery node process with its full command line.
pgrep -x sshdThe PID of sshd itself, not of anything merely mentioning ssh.
kill $(pgrep -f "celery worker")Stop the processes the pattern found.
何が動いていて何が資源を食っているかを見ます。止める前に何なのかを確かめるのが順番です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. pgrep は何をしますか。
pkill とまったく同じ規則で、一致するプロセスの PID だけを表示します。だから何かを殺す前の下見にちょうど向いています。
Q. どう打ちますか。
pgrep [-f] <pattern> — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは7個です。全部は man pgrep にあります。このコマンドはプロセスとシステムの仲間です。
関連するコマンド
man ページ: man pgrep