The top command in Linux provides a real-time view of running processes and system resource usage. From a single interactive screen you can check CPU load, memory consumption, load averages, and process activity all at once.
Run top without arguments to start the interactive monitor:
bashtop
The display splits into two areas:
The %Cpu(s) line is where most performance diagnosis starts. It breaks CPU time into labeled categories:
us — user-space processes (your applications)sy — kernel processesni — user-space processes running with an adjusted nice valueid — idle timewa — waiting for I/O; high wa means the disk or network is the bottleneck, not the CPUhi / si — hardware and software interrupt handlingst — CPU time stolen by the hypervisor; only meaningful on virtual machinesLoad average appears on the first header line as three numbers covering the 1, 5, and 15-minute windows. These represent the average number of runnable or uninterruptible tasks. Compare them to your CPU core count — a load average of 4.0 on a 4-core machine means the system is fully saturated.
The three memory columns are the source of the most confusion:
The memory used exclusively by a process is RES minus SHR. Shared libraries show up in RES for every process that uses them, so summing RES across all processes overstates actual memory consumption.
Process states appear in the S column: R (running), S (sleeping), D (uninterruptible sleep — waiting on I/O at the kernel level and cannot be killed normally), Z (zombie).
A zombie process has finished execution but stays in the process table because its parent has not read the exit status. A handful of zombies is harmless. A steadily growing count points to a bug in the parent process.
Press these keys while top is running:
| Key | Action |
|---|---|
P | Sort by CPU usage |
M | Sort by memory usage |
1 | Toggle per-CPU core display |
u | Filter by user |
k | Kill a process by PID |
r | Renice a process |
c | Toggle full command line |
q | Quit |
Press 1 to break the aggregate CPU line into individual cores. This is the most reliable way to catch a single thread pinning one core while the overall %Cpu still looks acceptable.
Command-line filters let you focus the display before it opens:
bashtop -u www-data # show only one user's processestop -p 1234,5678 # monitor specific PIDstop -d 5 # refresh every 5 secondstop -H # show individual threads instead of processes
Batch mode turns top into a scriptable snapshot tool by removing the interactive display entirely:
bashtop -b -n 1 > top.txt # single snapshot to a filetop -b -n 5 -d 1 > top-snapshots.txt # 5 snapshots at 1-second intervals
-b makes top safe for cron jobs, log collection, and automation pipelines where an interactive terminal is not available.
Learn the P, M, and 1 keys for everyday interactive use, and reach for -b -n 1 when you need a point-in-time snapshot for a script or log. Leave a comment below if you run into any issues.
The groupdel command in Linux removes a group from the system. It deletes the group's entry from /etc/group and /etc/gshadow,…
The wc command in Linux counts lines, words, characters, and bytes in files or standard input. It…
The usermod command in Linux modifies existing user account attributes. You can use it to manage group…
The sort command in Linux reads lines from files or standard input and writes them to standard…
The wall command in Linux sends a message to the terminals of all currently logged-in users. The…
journalctl queries logs collected by systemd-journald, the systemd logging daemon. It gives you structured access to kernel…