What it does
The top part shows uptime and load average, the number of tasks per state, CPU use (us user, sy system, ni niced, id idle, wa waiting for I/O, st stolen by the hypervisor) and memory and swap. Below is the process list, refreshed every 3 seconds.
Keys work while it runs: k kill, r renice, M sort by memory, P by CPU, 1 each CPU, q quit. With -b it writes plain text for logs and scripts.
How to write it
top [OPTION]...Main parts
k- Kill: send a signal to a PID.
r- Renice a PID.
P/M/T/N- Sort by CPU / memory / time / PID.
1- Show every CPU.
c- Show the full command line.
u- Show only one user.
f- Choose and sort columns.
H- Show threads.
V- Forest (tree) view.
E/e- Change memory units (summary / list).
W- Save the settings in ~/.config/procps/toprc.
h- Help.
q- Quit.
Options 19
Most used
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1Start top
top top - 10:52:01 up 2:54, 2 users, load average: 0.15, 0.10, 0.09 Tasks: 182 total, 1 running, 181 sleeping, 0 stopped, 0 zombie %Cpu(s): 1.2 us, 0.5 sy, 0.0 ni, 98.1 id, 0.2 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 3654.2 total, 2201.7 free, 812.4 used, 891.3 buff/cachePress q to leave.
2Sort by memory
top -o %MEMOr press M inside top.
3Only one user
top -u apacheWatch the web server processes.
4One process and its threads
top -H -p $(pidof chronyd)Which thread uses the CPU.
5Save one snapshot to a file
top -b -n 1 > /tmp/top-$(date +%H%M).txtEvidence for a slow-server ticket.
6Log every 10 seconds for one minute
top -b -d 10 -n 6 | grep -A 8 '^top' > /tmp/top.logA short performance log.
7Kill from top
topPress k, type the PID, press Enter (15) or type 9.
8Read the CPU line
top -b -n 1 | grep CpuHigh
wa= slow disk; highst= the hypervisor is overloaded; highsy= kernel work.9Find a crypto miner (security)
top -b -n 1 -o %CPU | head -12An unknown process at 100% CPU, often from /tmp or a strange user.
10Secure mode for a shared screen
top -sNobody can kill from this top.
Nothing matches this filter.
Watch out
- Load average counts waiting processes, also those waiting for disk. High load with low CPU use often means slow storage or NFS.
Files
~/.config/procps/toprc- Saved settings (W key).
Exit codes
0 | Done. |
1 | Error. |