top and htop

ps shows a snapshot. top and htop show live, updating views of your system.

top - The Classic

Terminal
$top
(interactive display - press 'q' to exit)

You'll see a dashboard that updates every few seconds.

Understanding top's Display

Header Section

top - 10:30:45 up 5 days, 3:22, 2 users, load average: 0.15, 0.10, 0.09
Tasks: 142 total,   1 running, 141 sleeping,   0 stopped,   0 zombie
%Cpu(s):  2.3 us,  1.0 sy,  0.0 ni, 96.5 id,  0.2 wa,  0.0 hi,  0.0 si
MiB Mem :  7976.5 total,  3245.2 free,  2134.8 used,  2596.5 buff/cache
MiB Swap:  2048.0 total,  2048.0 free,     0.0 used.  5432.1 avail Mem

Key metrics:

  • Load average: CPU demand over 1, 5, 15 minutes
  • Tasks: Process count by state
  • %Cpu: CPU time breakdown
  • Mem/Swap: Memory usage

Load Average

A load of 1.0 means 100% CPU capacity (on single core). With 4 cores, 4.0 is 100%. Below the core count = healthy.

Process List

ColumnMeaning
PIDProcess ID
USEROwner
PRPriority
NINice value
VIRTVirtual memory
RESResident (physical) memory
SHRShared memory
SStatus
%CPUCPU percentage
%MEMMemory percentage
TIME+Total CPU time
COMMANDCommand name

top Keyboard Commands

While in top:

KeyAction
qQuit
hHelp
kKill a process (enter PID)
rRenice (change priority)
MSort by memory
PSort by CPU
uFilter by user
1Show individual CPU cores
cShow full command path
Terminal
$# Press M to sort by memory, P to sort by CPU

htop - The Better top

htop is top with a better interface:

Terminal
$htop
(prettier interactive display)

Install htop

htop isn't always pre-installed:

hljs bash
sudo apt install htop  # Debian/Ubuntu
sudo yum install htop  # RHEL/CentOS

htop Advantages

  • Color-coded - easier to read
  • Mouse support - click to select/sort
  • Horizontal scrolling - see long commands
  • Tree view - built in (F5)
  • Search - F3 to search processes
  • Kill - F9 for kill menu

htop Keyboard

KeyAction
F1Help
F2Setup
F3Search
F4Filter
F5Tree view
F6Sort by
F9Kill
F10Quit
\Filter by command
/Search

Reading CPU/Memory Bars

In htop, the colored bars show:

CPU bars:

  • Blue: Low priority
  • Green: Normal user processes
  • Red: Kernel processes
  • Cyan: Virtualization

Memory bars:

  • Green: Used memory
  • Blue: Buffers
  • Orange: Cache

When to Use Which

ToolBest For
ps auxQuick snapshot, scripting
topLive monitoring, any system
htopInteractive investigation, kills
Knowledge Check

In top/htop, what does a load average of 4.0 on a 4-core system indicate?

Key Takeaways

  • top is the classic real-time process viewer
  • htop is a friendlier, more powerful alternative
  • Load average shows CPU demand (compare to core count)
  • Use keyboard shortcuts for sorting and killing
  • F9 in htop gives a convenient kill menu

Next: managing foreground and background processes.