top Command Guide for a Live Process Monitor
This guide helps you understand and use the top command, the classic live view of the processes consuming your system’s resources.
What is top, and Why Use It?
The top command opens a full-screen, auto-refreshing display of the processes running on your system — their CPU and memory usage, how long they have been running, and who started them. It also shows summary lines at the top: load average, task counts, and CPU states. It has been present on Unix systems for decades, so it is available on almost every machine you will ever log into.
Why Learn top?
- Always available: Every Linux server has
top, even minimal ones with nohtop. - The system heartbeat: The load average and CPU lines tell you at a glance whether a machine is healthy or thrashing.
- Built-in controls: Press a key to sort, kill, or renice a process without leaving the screen.
- Scriptable: The batch mode (
top -b) feeds monitoring scripts.
topis the vital-signs monitor of the Unix world: it never stops telling you how the system is doing.
1. Start the Interactive View
top
- The screen refreshes every few seconds;
- The header shows uptime, load average, task counts, and CPU percentages;
- The process table below can be sorted, filtered, and acted on with single keys.
Leave top at any time with q.
2. Understand the Process Table
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1234 alice 20 0 928.2m 60.1m 32.5m S 7.3 1.2 0:15.42 nginx
5678 bob 20 0 1.2g 320.4m 55.3m S 2.1 6.4 3:21.07 firefox
- PID: the process ID — the handle for
killand friends; - USER: who started it;
- PR and NI: priority — see
nice; - VIRT and RES: virtual and real memory used;
- S: state —
Ssleeping,Rrunning,Duninterruptible wait,Zzombie; - %CPU and %MEM: resource shares;
- COMMAND: the program name.
3. Sort the Display by CPU or Memory
P sort by %CPU (default)
M sort by %MEM
T sort by time running
< and > move the sort column left or right
- Press
P(shift+p) to sort by CPU andMfor memory — the two most common needs; - After sorting, the busiest processes rise to the top of the table;
- This is how you quickly find the runaway process.
4. Kill a Process from Inside top
k ask for a PID and send it a signal
- Press
k, type the PID, press Enter; topthen asks which signal — Enter sends the default (15, polite);- Type
9for SIGKILL when a process refuses to die; - See
killfor the full picture.
5. Change Priority from Inside top
r ask for a PID and its new nice value
- Press
r, type the PID, then the nice value from -20 to 19; - This is the interactive twin of
renice; - Lowering the nice value (more negative) gives a process more CPU.
6. Filter to One User or Search by Name
u ask for a username and show only that user's processes
o or O add a filter field on the fly
- Press
u, type a username, and the table shows only their processes — pressuagain with an empty name to see everything; - Press
oto interactively add a filter such asCOMMAND=nginx; - Filters stack, and pressing
=clears them.
7. Watch a Single Process by PID
top -p 1234
-prestricts the display to the given process ID;- Repeat the flag for several PIDs:
top -p 1234 -p 5678; - This is how you watch one specific process without the whole table.
8. Run in Batch Mode for Scripts
top -b -n 1 | head -20
-brunstopin batch (non-interactive) mode;-n 1takes exactly one iteration and exits;- The output is plain text, so it pipes into
head,grep, or a log.
Common Pitfalls
- Confusing VIRT with real memory: VIRT includes everything the process reserved; RES is what it actually holds in RAM. Judge memory pressure by RES and the %MEM column.
- Reading load average wrong: The three numbers are 1-, 5-, and 15-minute averages of runnable work. On a 4-core machine, a load of 4 is “fully busy,” not “broken.”
- Forgetting the refresh:
topupdates its own screen; if you are reading a frozen screenshot, the numbers are old.
Related Pages
| Page | Description |
|---|---|
ps | The snapshot view top keeps refreshing |
htop | The friendlier, colorful, mouse-capable monitor |
kill | Stop processes — also possible from inside top |
renice | Change priority — also possible from inside top |
watch | Re-run any command periodically |
top Cheatsheet
| Task | Command |
|---|---|
| Start the live view | top |
| Sort by CPU / memory | P / M |
| Kill a process | k, then PID, then signal |
| Renice a process | r, then PID, then nice value |
| Show one user’s processes | u, then username |
| Watch one PID | top -p 1234 |
| One-shot text output | top -b -n 1 |
| Leave | q |