Home·Terminal commands

top

Processes and system

Usage

top

Redraws the process list every few seconds; its flags differ completely between platforms, so a single snapshot is `-b -n 1` on Linux and `-l 1` on macOS.

Common flags

FlagMeaning
-b -n 1Batch mode, one refresh, then exit: safe to pipe or log (Linux).
-p <pid>Watch a single process (Linux).
-u <user>Only one user's processes (Linux).
-o cpuSort by CPU on macOS; -o mem sorts by memory.
-l 1One sample and exit on macOS (the equivalent of -b -n 1).
P / M / k / qKeys inside Linux top: sort by CPU, sort by memory, kill a PID, quit.

Examples

top -b -n 1 | head -20

A snapshot of the busiest processes, printable into a log (Linux).

top -o mem

Live list sorted by memory use (macOS).

top -p 1234

Follow one process only (Linux).

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 top do?

Redraws the process list every few seconds; its flags differ completely between platforms, so a single snapshot is `-b -n 1` on Linux and `-l 1` on macOS.

Q. How do I type it?

top — 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 top. This command sits under Processes and system.

Related commands

man page: man top