Monitoring

top & htop CLI

top and htop commands for process monitoring.

30 commands
Windows MacOS Linux
#process-monitoring #system

Basic Usage

Launch interactive process viewer
top
Launch htop with color and mouse support
htop
Run top in batch mode for one iteration
top -b -n 1
Start htop with 5-second refresh interval
htop -d 5
Show processes for a specific user
top -u www-data
Filter htop to show only root processes
htop -u root

Sorting

Start top sorted by memory usage
top -o %MEM
Start top sorted by CPU usage
top -o %CPU
Start top sorted by cumulative CPU time
top -o TIME+
Start htop sorted by memory percentage
htop --sort-key=PERCENT_MEM
Start htop sorted by CPU percentage
htop --sort-key=PERCENT_CPU

Filtering

Monitor only PID 1234
top -p 1234
Monitor multiple specific PIDs
top -p 1234,5678
Show only specific PID in htop
htop -p 1234
Display processes in tree view
htop -t
Show full command line for each process
top -c

Display Options

Show individual threads instead of processes
top -H
Save 5 snapshots to a file
top -b -n 5 > top_output.txt
Start htop in monochrome mode
htop -C
Display memory in gigabytes
top -E g
Show per-CPU core usage breakdown
top -1

Signals

Get top CPU consumers in batch mode
top -b -n 1 -o %CPU | head -20
Send graceful termination to a process
kill -SIGTERM 1234
Force-kill a process by PID
kill -9 1234
Terminate all processes of a user
killall -u www-data
Lower priority of a running process
renice -n 10 -p 1234
Raise priority of a running process
renice -n -5 -p 1234

Quick Commands

Launch interactive process viewer with color support
htop
Show top CPU-consuming processes in batch mode
top -b -n 1 -o %CPU
Monitor processes for a specific user
top -u www-data