Home·Terminal commands

ps

Processes and system

Usage

ps aux | ps -ef

Takes a one-off snapshot of the running processes; `ps aux` is the BSD spelling with no dash and `ps -ef` the POSIX one, and mixing the two is the usual mistake.

Common flags

FlagMeaning
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.

Examples

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.

What is running and what is eating the machine. Identifying it comes before killing it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does ps do?

Takes a one-off snapshot of the running processes; `ps aux` is the BSD spelling with no dash and `ps -ef` the POSIX one, and mixing the two is the usual mistake.

Q. How do I type it?

ps aux | ps -ef — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

6 are listed here; the full set is in man ps. This command sits under Processes and system.

Related commands

man page: man ps