top Command in Linux: Monitor Processes in Real Time
top is a command-line utility that displays running processes and system resource usage in real time. It helps you inspect CPU usage, memory consumption, load averages, and process activity from a single interactive view.
This guide explains how to use top to monitor your system and quickly identify resource-heavy processes.
top Command Syntax
The syntax for the top command is as follows:
top [OPTIONS]Run top without arguments to open the interactive monitor:
topUnderstanding the top Output
The screen is split into two areas:
- Summary area — system-wide metrics displayed in the header lines
- Task area — per-process metrics listed below the header
A typical top header looks like this:
top - 14:32:01 up 3 days, 4:12, 2 users, load average: 0.45, 0.31, 0.28
Tasks: 213 total, 1 running, 212 sleeping, 0 stopped, 0 zombie
%Cpu(s): 3.2 us, 1.1 sy, 0.0 ni, 95.3 id, 0.2 wa, 0.0 hi, 0.1 si, 0.0 st
MiB Mem : 15886.7 total, 8231.4 free, 4912.5 used, 2742.8 buff/cache
MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 10374.2 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1234 www-data 20 0 123456 45678 9012 S 4.3 0.3 0:42.31 nginx
987 mysql 20 0 987654 321098 12345 S 1.7 2.0 3:12.04 mysqld
5678 root 20 0 65432 5678 3456 S 0.0 0.0 0:00.12 sshd
CPU State Percentages
The %Cpu(s) line breaks CPU time into the following states:
-
us— time running user-space (non-kernel) processes -
sy— time running kernel processes -
ni— time running user processes with a manually adjusted nice value -
id— idle time -
wa— time waiting for I/O to complete -
hi— time handling hardware interrupt requests -
si— time handling software interrupt requests -
st— time stolen from this virtual machine by the hypervisor (relevant on VMs)
High wa typically points to a disk or network I/O bottleneck. High us or sy points to CPU pressure. For memory details, see the free
command. For load average context, see uptime
.
Task Area Columns
| Column | Description |
|---|---|
PID |
Process ID |
USER |
Owner of the process |
PR |
Scheduling priority assigned by the kernel |
NI |
Nice value (-20 = highest priority, 19 = lowest) |
VIRT |
Total virtual memory the process has mapped |
RES |
Resident set size — physical RAM currently in use |
SHR |
Shared memory with other processes |
S |
Process state: R running, S sleeping, D uninterruptible, Z zombie |
%CPU |
CPU usage since the last refresh |
%MEM |
Percentage of physical RAM in use |
TIME+ |
Total CPU time consumed since the process started |
COMMAND |
Process name or full command line (toggle with c) |
Common Interactive Controls
Press these keys while top is running:
| Key | Action |
|---|---|
q |
Quit top
|
h |
Show help |
k |
Kill a process by PID |
r |
Renice a process |
P |
Sort by CPU usage |
M |
Sort by memory usage |
N |
Sort by PID |
T |
Sort by running time |
1 |
Toggle per-CPU core display |
c |
Toggle full command line |
u |
Filter by user |
Refresh Interval and Batch Mode
To change the refresh interval (seconds), use -d:
top -d 2To run top in batch mode (non-interactive), use -b. This is useful for scripts and logs:
top -b -n 1To capture multiple snapshots:
top -b -n 5 -d 1 > top-snapshot.txtFiltering and Sorting
Start top with a user filter:
top -u rootTo monitor a specific process by PID, use -p:
top -p 1234Pass a comma-separated list to monitor multiple PIDs at once:
top -p 1234,5678To show individual threads instead of processes, use -H:
top -HThread view is useful when profiling multi-threaded applications — each thread appears as a separate row with its own CPU and memory usage.
Inside top, use:
-
Pto sort by CPU -
Mto sort by memory -
uto show a specific user
For deeper process filtering, combine top with ps
, pgrep
, and kill
.
Quick Reference
| Command | Description |
|---|---|
top |
Start interactive process monitor |
top -d 2 |
Refresh every 2 seconds |
top -u user |
Show only a specific user’s processes |
top -p PID |
Monitor a specific process by PID |
top -H |
Show individual threads |
top -b -n 1 |
Single non-interactive snapshot |
top -b -n 5 -d 1 |
Collect 5 snapshots at 1-second intervals |
Troubleshooting
top is not installed
Install the procps package (procps-ng on some distributions), then run top again.
Display refresh is too fast or too slow
Use -d to tune the refresh rate, for example top -d 2.
Cannot kill or renice a process
You may not own the process. Use sudo or run as a user with sufficient privileges.
FAQ
What is the difference between top and htop?
top is available by default on most Linux systems and is lightweight. htop provides a richer interactive UI with color coding, mouse support, and easier navigation, but requires a separate installation.
What does load average mean?
Load average shows the average number of runnable or uninterruptible tasks over the last 1, 5, and 15 minutes. A value above the number of CPU cores indicates the system is under pressure. See uptime
for more detail.
What is a zombie process? A zombie process has finished execution but its entry remains in the process table because the parent process has not yet read its exit status. A small number of zombie processes is harmless; a growing count may indicate a bug in the parent application.
What do VIRT, RES, and SHR mean?
VIRT is the total virtual address space the process has reserved. RES is the actual physical RAM currently in use. SHR is the portion of RES that is shared with other processes (for example, shared libraries). RES minus SHR gives the memory used exclusively by that process.
Can I save top output to a file?
Yes. Use batch mode, for example: top -b -n 1 > top.txt.
Conclusion
The top command is one of the fastest ways to inspect process activity and system load in real time. Learn the interactive keys and sort options to diagnose performance issues quickly.
If you have any questions, feel free to leave a comment below.






