Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

Linux & Mac & Bash Command Dictionary

  1. Home
  2. Linux & Mac & Bash Command Dictionary
  3. top / htop (Real-Time Process Monitoring)

top / htop (Real-Time Process Monitoring)

top is a real-time process monitoring tool included by default with Linux. It continuously displays CPU usage, memory usage, and load average in the terminal, making it useful for identifying bottlenecks and finding runaway processes. htop is an enhanced version of top that supports color output, mouse interaction, and tree view, allowing you to inspect processes and send signals with an intuitive interface.

Syntax

# -----------------------------------------------
#  top startup options
# -----------------------------------------------

# top
#   → Displays a real-time process list
#   Example: top

# top -d {seconds}
#   → Starts with the specified screen refresh interval (in seconds)
#   Example: top -d 2

# top -u {username}
#   → Shows only processes belonging to the specified user
#   Example: top -u goku

# top -p {PID} [{PID} ...]
#   → Monitors only the processes with the specified PIDs
#   Example: top -p 1234 -p 5678

# top -b -n {count}
#   → Runs in batch mode and exits after the specified number of iterations
#   → Useful for redirecting output to a log file or piping to another command
#   Example: top -b -n 3 > /tmp/top_snapshot.txt

# top -H
#   → Displays processes at the thread level
#   Example: top -H

# -----------------------------------------------
#  top interactive key bindings
# -----------------------------------------------

# q        → Quit top
# k        → Enter a PID to send a signal to a process (default: SIGTERM)
# r        → Enter a PID to change the nice value of a process (renice)
# M        → Sort by memory usage (%MEM) in descending order
# P        → Sort by CPU usage (%CPU) in descending order (default)
# T        → Sort by cumulative CPU time (TIME+) in descending order
# u        → Filter processes by user
# c        → Toggle the command display between full path and command name
# 1        → Toggle between individual CPU core display and combined display
# H        → Toggle thread display on/off
# i        → Hide idle (0% CPU) processes
# f        → Open the field customization screen
# W        → Save the current display settings to ~/.toprc
# space    → Refresh the screen immediately

# -----------------------------------------------
#  htop startup options
# -----------------------------------------------

# htop
#   → Starts htop (supports color output and mouse interaction)
#   Example: htop

# htop -u {username}
#   → Shows only processes belonging to the specified user
#   Example: htop -u vegeta

# htop -p {PID}[,{PID} ...]
#   → Monitors only the processes with the specified PIDs
#   Example: htop -p 1234,5678

# htop -d {interval × 10ms}
#   → Sets the refresh interval in deciseconds (20 = 2 seconds)
#   Example: htop -d 20

# htop -t
#   → Starts in tree view (shows parent-child relationships)
#   Example: htop -t

# -----------------------------------------------
#  htop interactive key bindings
# -----------------------------------------------

# F1 / h   → Show help
# F2 / S   → Open settings (color scheme, columns, meter selection)
# F3 / /   → Search processes by name
# F4 / \   → Filter processes by name
# F5 / t   → Toggle tree view on/off
# F6 / >   → Select the column to sort by
# F7 / [   → Decrease the nice value of the selected process (raise priority)
# F8 / ]   → Increase the nice value of the selected process (lower priority)
# F9 / k   → Send a signal to the selected process
# F10 / q  → Quit htop
# space    → Tag a process (for bulk operations on multiple processes)
# u        → Filter processes by user

Reference

ItemDescription
load averageThe average number of processes waiting for CPU time over the past 1, 5, and 15 minutes. When the value exceeds the number of CPU cores, the system is under high load. For example, on a 4-core server, load average: 4.00 means all cores are fully utilized, and values above 8.00 indicate a processing backlog.
%us (user space CPU usage)The percentage of CPU consumed by user-space processes (applications). Indicates the processing load of the application itself.
%sy (kernel space CPU usage)The percentage of CPU used by kernel operations such as system calls and I/O processing. A high value suggests heavy disk I/O or network activity.
%id (idle rate)The percentage of time the CPU is idle. It equals 100% minus %us + %sy + other. The lower this value, the busier the CPU.
%wa (I/O wait rate)The percentage of time the CPU spends waiting for disk or network I/O to complete. A high value suggests a storage bottleneck.
PR (priority)The scheduling priority actually used by the kernel. Lower values indicate higher priority.
NI (nice value)A user-configurable priority adjustment value, ranging from -20 (highest priority) to 19 (lowest priority). Can be changed with the nice or renice command.
VIRT (virtual memory size)The total virtual memory allocated by the process. This includes shared libraries and swap space, so it is larger than the actual memory consumed.
RES (resident memory size)The amount of physical RAM actually used by the process. This is the most relevant value for understanding real memory consumption.
SHR (shared memory size)The amount of memory shared with other processes, such as shared libraries. Subtracting this from RES gives the memory used exclusively by the process.
S (process state)The current state of the process: R (running), S (sleeping), D (uninterruptible sleep / waiting for I/O), Z (zombie), or T (stopped).
TIME+ (cumulative CPU time)The total CPU time consumed by the process since it started. Useful for tracking the long-term CPU usage trend of resident processes.

Examples

Sample output of top
$ top
top - 14:23:05 up 12 days,  3:44,  2 users,  load average: 1.42, 0.87, 0.65
Tasks: 218 total,   2 running, 216 sleeping,   0 stopped,   0 zombie
%Cpu(s): 18.3 us,  4.2 sy,  0.0 ni, 76.1 id,  1.2 wa,  0.0 hi,  0.2 si,  0.0 st
MiB Mem :  15872.0 total,   3421.4 free,   8654.2 used,   3796.4 buff/cache
MiB Swap:   4096.0 total,   3988.1 free,    107.9 used.   6592.3 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
 1001 goku      20   0 3254812 412340  54320 R  42.3   2.5   8:12.34 kamehameha
 1002 vegeta    20   0 2183204 228900  41200 S  18.7   1.4   3:44.21 final_flash
 1003 piccolo   20   0  986432  98712  22100 S   5.2   0.6   1:23.07 makankosappo
 1004 krillin   20   0  524288  52480  18900 S   2.1   0.3   0:45.18 destructo_disc
 1005 trunks    20   0  768000  76800  21000 S   1.0   0.5   0:12.55 burning_attack
    1 root      20   0  168940  13508   8820 S   0.0   0.1   0:05.42 systemd
  987 root      20   0  421312  31200  20100 S   0.0   0.2   0:02.16 sshd

# load average: 1.42, 0.87, 0.65
#   → Average load over the past 1, 5, and 15 minutes
#   → On a 4-core server, 1.42 still leaves headroom
#   → The 1-minute value (1.42) is higher than the 15-minute value (0.65), indicating increasing recent load
#
# %Cpu(s): 18.3 us, 4.2 sy, 76.1 id, 1.2 wa
#   → User space is using 18.3%, kernel space is using 4.2%
#   → Idle at 76.1%, so the system still has capacity
#   → I/O wait at 1.2% indicates minor disk I/O activity
#
# PID 1001 goku's kamehameha process is consuming 42.3% CPU
# S=R (Running) means this process is actively using the CPU
Common command options
# -----------------------------------------------
#  Save top output to a file using batch mode
# -----------------------------------------------

# Use -b for batch mode and -n to specify the number of iterations
# Useful for capturing a load snapshot
top -b -n 1 > /tmp/top_snapshot.txt

# Save only the top 10 processes by CPU usage
top -b -n 1 | head -n 17 > /tmp/top_top10.txt

# -----------------------------------------------
#  Monitor only a specific user's processes
# -----------------------------------------------

# Show only goku's processes
top -u goku

# With htop, use the -u option as well
htop -u goku

# -----------------------------------------------
#  Choosing between top and htop
# -----------------------------------------------

# top: a standard tool available on any server
#   → Works immediately after SSH login
#   → Well-suited for scripting and batch processing (with the -b option)
top -d 3

# htop: requires installation but offers a much better user experience
#   → F3 for process name search, F4 for filtering — both intuitive
#   → Tree view (F5) makes parent-child relationships easy to understand
#   → Click column headers with the mouse to sort
htop -t

# -----------------------------------------------
#  Installing htop
# -----------------------------------------------

# Debian / Ubuntu
sudo apt install htop

# RHEL / AlmaLinux / Rocky Linux
sudo dnf install htop

Run the following command:

$ top -b -n 1 | head -n 17
top - 14:23:05 up 12 days,  3:44,  2 users,  load average: 1.42, 0.87, 0.65
Tasks: 218 total,   2 running, 216 sleeping,   0 stopped,   0 zombie
%Cpu(s): 18.3 us,  4.2 sy,  0.0 ni, 76.1 id,  1.2 wa,  0.0 hi,  0.2 si,  0.0 st
MiB Mem :  15872.0 total,   3421.4 free,   8654.2 used,   3796.4 buff/cache
MiB Swap:   4096.0 total,   3988.1 free,    107.9 used.   6592.3 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
 1001 goku      20   0 3254812 412340  54320 R  42.3   2.5   8:12.34 kamehameha
 1002 vegeta    20   0 2183204 228900  41200 S  18.7   1.4   3:44.21 final_flash
 1003 piccolo   20   0  986432  98712  22100 S   5.2   0.6   1:23.07 makankosappo
 1004 krillin   20   0  524288  52480  18900 S   2.1   0.3   0:45.18 destructo_disc
 1005 trunks    20   0  768000  76800  21000 S   1.0   0.5   0:12.55 burning_attack
    1 root      20   0  168940  13508   8820 S   0.0   0.1   0:05.42 systemd
  987 root      20   0  421312  31200  20100 S   0.0   0.2   0:02.16 sshd

Overview

top is a real-time process monitoring tool included by default with Linux. It is typically the first command you run after SSH-ing into a server when something feels slow, as it lets you see load average, CPU usage, and memory usage all on one screen. When interpreting load average, compare it against the number of CPU cores — on a 4-core server, for example, processing queues start to form once the value exceeds 4.00. If %wa (I/O wait) is high, a storage or network I/O bottleneck is likely, so it is effective to investigate further with vmstat / iostat. For long-term trend analysis, use sar / sysstat to accumulate data over time. htop is an enhanced version of top with color output, mouse support, and tree view. A common pattern is to use htop for interactive investigation and top -b (batch mode) for scripts and automation.

If you find any errors or copyright issues, please .