Operations 10 min read

Master Linux ‘top’: Real-Time Process Monitoring and Performance Tuning

Learn how to use Linux’s top command to dynamically monitor process activity, interpret CPU, memory, and swap statistics, customize displayed columns, and apply useful shortcuts for sorting and filtering, enabling effective real-time system performance analysis and troubleshooting.

Efficient Ops
Efficient Ops
Efficient Ops
Master Linux ‘top’: Real-Time Process Monitoring and Performance Tuning

top: dynamic process monitoring tool for Linux, similar to Windows Task Manager.

Below is detailed usage.

Summary Information Section

The first five lines show overall system statistics.

Line 1 shows task‑queue info similar to the

uptime

command output:

<code>07:25:19   Current time
up 246 days   System uptime
2:34
4 user   Number of logged‑in users
load average: 2.51, 2.53, 2.53   System load (average length of task queue) for 1, 5, 15 minutes.</code>

Lines 2‑3 display tasks and CPU information. Example:

<code>Tasks:
 total   total number of processes
 running   processes running
 sleeping   processes sleeping
 stopped   stopped processes
 zombie   zombie processes</code>

CPU usage breakdown:

<code>Cpu(s):
 us   user space CPU percentage
 sy   kernel space CPU percentage
 ni   user processes with changed priority CPU percentage
 id   idle CPU percentage
 wa   I/O wait CPU percentage
 hi   hardware interrupt CPU percentage
 si   software interrupt CPU percentage
 st   steal time (CPU time taken by hypervisor when it services other virtual CPUs)</code>

Memory usage:

<code>Mem:
 total   total physical memory
 free   free memory
 used   used memory
 buff/cache   memory used as kernel cache</code>

Swap usage:

<code>Swap:
 total   total swap space
 free   free swap space
 used   used swap space
 avail Mem   available swap space (pages that have been swapped out but not overwritten)</code>

Process Information Section

Below the summary, detailed per‑process columns are listed. Key columns include:

<code>PID   process ID
PPID   parent process ID
RUSER   real user name
UID   user ID of process owner
USER   username of process owner
GROUP   group name of process owner
TTY   terminal name (or ? if not started from a terminal)
PR   priority
NI   nice value (negative = higher priority)
P   last CPU used (relevant on multi‑CPU systems)
%CPU   CPU usage percentage since last update
TIME   total CPU time used (seconds)
TIME+   total CPU time used (hundredths of a second)
%MEM   physical memory usage percentage
VIRT   virtual memory size (KB)
SWAP   swapped‑out virtual memory size (KB)
RES   resident memory size (KB)
CODE   code segment size (KB)
DATA   data + stack size (KB)
SHR   shared memory size (KB)
... (other fields omitted for brevity)</code>

By default, top shows the most important columns: PID, USER, PR, NI, VIRT, RES, SHR, S, %CPU, %MEM, TIME+, COMMAND. Use the

f

key to select columns,

o

to reorder, and

F

to choose the sorting column.

top Command Options

<code>top [-] [d] [p] [q] [C] [S] [s] [n]
-d <seconds>   set delay between screen refreshes (default 5s)
-b -n 2 > /tmp/top.txt   batch mode, output two iterations to file
-p <pid>   monitor specific PID (e.g., top -p 1)
-q   run with no delay (high priority if run as root)
-S   enable cumulative mode
-s   safe mode (disable interactive commands)
-i   hide idle or zombie processes
-c   show full command line</code>

Common top Operations

Record top output every 2.5 seconds for 5 iterations:

top -b -d 2.5 -n 5 > performance.txt

(note:

-b

is required for file output).

Sort quickly by %CPU, %MEM, TIME+: press P , M , or T respectively. Use R for ascending order.

Show/hide columns with f , reorder with o , and select sorting column with F .

CPU Steal Time

When running virtual machines (e.g., Amazon EC2), steal time (

%st

) indicates the portion of CPU time the hypervisor takes away from the VM. High values suggest severe performance degradation.

In virtual environments, multiple VMs share physical CPU slices. Even if a VM is allocated 1/4 of a CPU, it can exceed that limit if the host is not fully utilized.

top can display real‑time metrics such as %id (idle), %wa (I/O wait), and %st (steal time). Low %id means high CPU load; high %wa indicates the CPU is waiting for I/O operations.

PerformanceLinuxcpumemorysystem monitoringtop
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.