Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

top

Watch the processes live, sorted by CPU, with load, CPU and memory totals — and kill or renice from it.

Level
RHCSA exam
Group
Processes and jobs
Needs root
No
Package
procps-ng

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

-b, --batch
Batch mode: plain text output (for logs and pipes).
-n, --iterations NUMBER
Stop after NUMBER updates.
-d, --delay SECONDS
Seconds between updates.
-p, --pid PIDLIST
Only these PIDs.
-u, --filter-only-euser USER
Only this effective user.
-U, --filter-any-user USER
Any user ID match (real, effective, saved, file).
-o, --sort-override FIELD
Sort by this field, like -o %MEM.
-H, --threads-show
Show threads.
-c, --cmdline-toggle
Start with full command lines.
-i, --idle-toggle
Hide idle processes.
-S, --accum-time-toggle
Cumulative time (with dead children).
-E, --scale-summary-mem k|m|g|t|p|e
Units in the summary.
-e, --scale-task-mem k|m|g|t|p
Units in the list.
-O, --list-fields
List the field names.
-s, --secure-mode
Secure mode (no kill or renice).
-w, --width [COLUMNS]
Output width in batch mode.
-1, --single-cpu-toggle
Start with each CPU shown (or one line).
-h, --help
Show help.
-V, --version
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 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/cache

    Press q to leave.

  2. 2Sort by memory

    top -o %MEM

    Or press M inside top.

  3. 3Only one user

    top -u apache

    Watch the web server processes.

  4. 4One process and its threads

    top -H -p $(pidof chronyd)

    Which thread uses the CPU.

  5. 5Save one snapshot to a file

    top -b -n 1 > /tmp/top-$(date +%H%M).txt

    Evidence for a slow-server ticket.

  6. 6Log every 10 seconds for one minute

    top -b -d 10 -n 6 | grep -A 8 '^top' > /tmp/top.log

    A short performance log.

  7. 7Kill from top

    top

    Press k, type the PID, press Enter (15) or type 9.

  8. 8Read the CPU line

    top -b -n 1 | grep Cpu

    High wa = slow disk; high st = the hypervisor is overloaded; high sy = kernel work.

  9. 9Find a crypto miner (security)

    top -b -n 1 -o %CPU | head -12

    An unknown process at 100% CPU, often from /tmp or a strange user.

  10. 10Secure mode for a shared screen

    top -s

    Nobody can kill from this top.

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

0Done.
1Error.