LLI Wiki — My Digital Knowledge Base

Monitor processes with top, iotop and pidstat

Read the CPU fields of top, its shortcuts, filter by command line and measure I/O per process with iotop and pidstat.

Commands and shortcuts to watch CPU load, memory and disk I/O on Linux with top, iotop and pidstat.

Read the CPU fields in top

The %Cpu(s) line of top breaks down the CPU time:

Field Meaning
us Time spent in user space
sy Time spent in the kernel
ni Time spent in user processes with a changed priority (nice)
id Idle time
wa Time waiting for I/O (for example the disk)
hi Time spent handling hardware interrupts
si Time spent handling software interrupts
st Time taken from the virtual machine by the hypervisor

Shortcuts in top

Key Effect
P Sort by CPU usage
M Sort by memory usage
T Sort by accumulated CPU time
R Reverse the sort order
t Show or hide the summary lines (tasks, CPU)
1 Show or hide the per-core detail
E Change the memory unit of the summary (KB, MB, GB)
z Turn colours on or off
x Highlight the sort column
b Turn bold on or off for the highlighted column
V Show processes as a tree (forest mode)
c Show or hide the full command line

Filter processes by command line

top -c -p $(pgrep -d',' -f string_to_match_in_cmd_line)

-c shows the full command. pgrep -d',' builds the comma-separated PID list that top -p expects.

Measure I/O per process

pidstat -dl 20
iotop -oPa

top and ps equivalents

top ps Meaning
VIRT VSZ Virtual memory size
RES RSS Resident (physical) memory of the process

Cgroups

cat /proc/cgroups
systemctl status
cat /proc/self/cgroup
systemd-cgtop

These commands list the cgroup controllers, show the systemd tree, display the cgroup of the current shell and show consumption per cgroup.

Remarks

Mastodon LLIMastodon SocialFosstodon