Master Linux top: A Complete Real‑Time Process Monitoring Guide
This article provides a thorough walkthrough of the Linux top command, explaining its default output, the meaning of each field, how to navigate and customize the interactive interface, and how to use command‑line options for batch mode, refresh intervals, user filtering, and more.
1. Top Command Output
The top utility displays a live snapshot of system activity, showing overall load, task summary, CPU states, memory usage, and a table of processes. The first few lines summarize system uptime, average load, number of logged‑in users, and the load averages for the past 1, 5, and 15 minutes. Press l to toggle this view.
1.1 System Uptime and Load Average
These fields correspond to the output of uptime:
Current time
System uptime
Number of logged‑in users
Load averages for the last 1, 5, and 15 minutes
Use the l command to switch the display.
1.2 Tasks Summary
The second line shows a summary of all processes, including counts of running, sleeping, stopped, and zombie tasks. Press t to toggle this view.
1.3 CPU States
The next line reports CPU usage percentages for various modes:
us – user processes (non‑nice)
sy – kernel processes
ni – user processes with a nice value
wa – I/O wait
hi – hardware interrupts
si – software interrupts
st – stolen time (virtualized environments)
Press t to toggle the CPU view.
1.4 Memory Usage
Two lines mimic the free command, showing physical memory and swap usage (total, used, free, buffers). Press m to toggle the memory view.
1.5 Process Columns
Below the system summary, each process is listed in columns. The default columns are:
PID – process identifier
USER – owning user name
PR – scheduling priority (e.g., rt for real‑time)
NI – nice value (lower = higher priority)
VIRT – virtual memory size
RES – resident (non‑swap) memory size
SHR – shared memory size
S – process state (D, R, S, T, Z)
%CPU – CPU usage since last update
%MEM – percentage of physical memory used
TIME+ – total CPU time consumed
COMMAND – command line (full path can be toggled)
2. Interactive Commands
While top runs, you can press keys to modify the display:
h / ? – show the help screen.
Enter / Space – refresh immediately.
A – switch between the four predefined field groups (Def, Job, Mem, Usr). Use a and w to move between windows, g to jump to a specific window.
B – toggle bold highlighting for important rows.
d / s – set a custom refresh interval (in seconds).
l / t / m – toggle load, task/CPU, and memory sections.
f – open the field‑management screen; * marks selected fields. Use arrow keys to navigate, < / > to move fields left/right, and Enter to confirm.
R – reverse sort order.
c – toggle display of the full command line path.
i – show or hide idle tasks.
V – switch to tree view.
Z – open the color‑scheme selector (up to eight colors for the four windows).
z – enable/disable colored output.
x / y – highlight the sorted column (x) or the running process row (y); requires color mode.
u – filter processes by a specific user (blank shows all).
n / # – set the maximum number of tasks displayed.
k – send a signal to terminate a task (the most important interactive command).
r – change a task’s scheduling priority.
3. Command‑Line Options
All interactive commands have corresponding command‑line flags, allowing you to start top with a predefined configuration: -b – batch mode (useful for redirecting output to a file). -c – remember the last state of the command‑line display toggle. -d <seconds> – set the refresh delay (e.g., top -d 1 for a 1‑second interval). -i – invert the previous idle‑process setting. -n <iterations> – exit after the specified number of updates (e.g., top -n 3). -p <PID> – monitor a specific PID (PID 0 monitors the top process itself). -u <user> or -U <UID> – show only processes belonging to the given user; these options are mutually exclusive with -p.
Attempting to combine mutually exclusive options results in an error such as “conflicting process selections”.
By mastering both the interactive keys and the command‑line flags, you can tailor top to a wide range of monitoring scenarios, from quick ad‑hoc checks to scripted batch reports.
$ top -d 1
$ top -n 3
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
