top – display and manage running processes

top command linux
top command linux

top provides a real-time view of running processes. It shows CPU, memory usage, and allows you to manage processes interactively.

Synopsis

top [OPTIONS]

Interactive Commands

KeyAction
qQuit
hHelp
kKill process (prompts for PID)
rRenice process (change priority)
uFilter by user
MSort by memory
PSort by CPU
TSort by time
1Toggle per-CPU stats
cToggle full command path

Common Options

OptionDescription
-d SECSUpdate interval
-n NUMNumber of iterations
-u USERShow only user’s processes
-p PIDMonitor specific PIDs
-bBatch mode (for scripts)

Examples

Basic usage

$ top

Update every 2 seconds

$ top -d 2

Show specific user

$ top -u greys

Batch mode (for scripts)

$ top -b -n 1 | head -20

Monitor specific processes

$ top -p 1234,5678

Understanding the Display

Header Section

top - 14:30:00 up 7 days,  3:45,  2 users,  load average: 0.15, 0.20, 0.18
Tasks: 234 total,   1 running, 233 sleeping,   0 stopped,   0 zombie
%Cpu(s):  5.2 us,  1.3 sy,  0.0 ni, 93.0 id,  0.5 wa,  0.0 hi,  0.0 si
MiB Mem :  15921.4 total,   2345.6 free,   8765.4 used,   4810.4 buff/cache
  • Load average: 1/5/15 minute CPU load
  • us: User CPU time
  • sy: System CPU time
  • id: Idle
  • wa: Waiting for I/O

Process Columns

ColumnMeaning
PIDProcess ID
USEROwner
PRPriority
NINice value
VIRTVirtual memory
RESResident memory
SHRShared memory
SState (R=running, S=sleeping)
%CPUCPU percentage
%MEMMemory percentage
TIME+Total CPU time
COMMANDCommand name

Tips

  • Use htop: More user-friendly, with colors and mouse support
  • Sort by memory: Press M to find memory hogs
  • Kill from top: Press k, enter PID, then signal (15 or 9)
  • Save config: Press W to write current settings
  • macOS: Use top -o cpu to sort by CPU

See Also

  • htop — Interactive process viewer (recommended)
  • ps — Snapshot of processes
  • kill — Send signals to processes
  • free — Memory usage

Tutorials