ps

プロセスとシステム

書き方

ps aux | ps -ef

いま動いているプロセスを一度だけ写し取ります。`ps aux` はダッシュのない BSD 形式、`ps -ef` は POSIX 形式で、この二つを混ぜるのがよくある間違いです。

よく使うオプション

オプション意味
auxBSD form (no dash): every process of every user, including those with no terminal. Works on Linux and macOS.
-efPOSIX 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,commChoose exactly which columns to print.
--sort=-%cpuSort by CPU, highest first. GNU procps only; macOS ps has no --sort.

ps aux | grep -i nginx

Find the nginx processes and their PIDs.

ps -eo pid,%mem,comm --sort=-%mem | head

The 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