ps
プロセスとシステム
書き方
ps aux | ps -efいま動いているプロセスを一度だけ写し取ります。`ps aux` はダッシュのない BSD 形式、`ps -ef` は POSIX 形式で、この二つを混ぜるのがよくある間違いです。
よく使うオプション
| オプション | 意味 |
|---|---|
| aux | BSD form (no dash): every process of every user, including those with no terminal. Works on Linux and macOS. |
| -ef | POSIX form: the same list with the parent PID and the full command line. |
| -p <pid> | Show one process only. |
| -u <user> | Only the processes of that user. |
| -o pid,ppid,%cpu,%mem,comm | Choose exactly which columns to print. |
| --sort=-%cpu | Sort by CPU, highest first. GNU procps only; macOS ps has no --sort. |
例
ps aux | grep -i nginxFind the nginx processes and their PIDs.
ps -eo pid,%mem,comm --sort=-%mem | headThe ten processes using the most memory (Linux).
ps -p 1234 -o etime=How long PID 1234 has been running, with no header.
何が動いていて何が資源を食っているかを見ます。止める前に何なのかを確かめるのが順番です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. ps は何をしますか。
いま動いているプロセスを一度だけ写し取ります。`ps aux` はダッシュのない BSD 形式、`ps -ef` は POSIX 形式で、この二つを混ぜるのがよくある間違いです。
Q. どう打ちますか。
ps aux | ps -ef — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは6個です。全部は man ps にあります。このコマンドはプロセスとシステムの仲間です。
関連するコマンド
man ページ: man ps