htop Command in Linux: Interactive Process Viewer and Manager
Learn htop command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.
10 min read
Learn htop command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.
- What htop Does and When to Use It
- Availability and Installation Across Linux Distributions
- Command Syntax, Arguments, and Exit Status Codes
For interactive server troubleshooting, the htop command in linux is one of the first packages system administrators install on a new machine. Originally created by Hisham Muhammad and now maintained by the community at htop.dev, htop modernizes classic top with an intuitive terminal user interface (TUI) built on libncursesw.
The htop command in Linux is an interactive, ncurses-based process viewer and system monitor that enhances traditional top with per-core color-coded CPU and memory gauges, full vertical and horizontal scrolling, mouse click support, live tree visualization (F5), instant substring filtering (F4), and direct signal or nice-level management (F9/F7/F8) without typing PIDs.
Unlike top, which requires memorizing single-letter case-sensitive hotkeys and typing numeric PIDs to kill or renice tasks, htop lets you scroll vertically through the entire process list with the arrow keys, scroll horizontally to read long command-line flags, click column headers with your mouse to change sort order, select multiple processes with the Space bar, and send signals via an on-screen menu (F9).
Modern releases of htop (3.x+) also integrate deep Linux kernel observability directly into the process viewer: you can press s to attach strace live to the highlighted process, press l to list its open files and sockets via lsof, and view per-process disk read/write rates, pressure stall information (PSI), and systemd cgroup slices across customizable tabs.
What htop Does and When to Use It
Like top, htop polls the Linux /proc and /sys pseudo-filesystems on each refresh interval (default 1.5 seconds). In addition to reading /proc/stat, /proc/meminfo, and /proc/PID/stat, htop reads /proc/PID/io (when run with sufficient permissions) to calculate real-time per-process disk I/O throughput, /proc/pressure/{cpu,memory,io} for Linux Kernel Pressure Stall Information (PSI), and /sys/class/hwmon for CPU core temperatures.
Understanding the color coding inside htop's top meter bars gives you an instant visual breakdown of system health. In the CPU bar: Blue represents low-priority (niced) user processes, Green represents normal user-space processes, Red represents kernel system time (syscalls and IRQ handling), and Cyan/Grey represents I/O wait or hypervisor steal time. In the Memory bar: Green is used memory by processes, Blue is kernel buffers, and Yellow/Orange is reclaimable filesystem page cache.
Under the hood, htop gathers runtime telemetry or dispatches control signals by reading virtual filesystems mounted at /proc and /sys, or by communicating with PID 1 (systemd) over D-Bus. Using flags such as -d, -u, -p, -s turns raw process and service tables into actionable diagnostics during incident response.
Availability and Installation Across Linux Distributions
The htop utility is packaged in htop across mainstream Linux distributions. It is pre-installed on standard Ubuntu, Debian, RHEL, Rocky Linux, AlmaLinux, Fedora, and Arch Linux systems, while minimal container images may require manual installation:
Before running administrative tasks or automation scripts, verify whether htop is installed and inspect which binary path and version your shell resolves:
type -a htop
htop --version 2>/dev/null || man -f htop
# Illustrative output (reviewed against documentation)
htop is /usr/bin/htop
htop (htop)
# Debian / Ubuntu
sudo apt-get update && sudo apt-get install -y htop
# RHEL / Rocky / AlmaLinux / Fedora
sudo dnf install -y htop
# Arch Linux
sudo pacman -S --noconfirm htop
# Alpine Linux
sudo apk add --no-cache htop
Command Syntax, Arguments, and Exit Status Codes
htop [OPTIONS]
You can launch htop with no arguments for the full interactive dashboard, or pass startup flags to jump directly to a specific view: htop -u username filters to a single user, htop -p PID1,PID2 watches only selected PIDs, htop -t opens directly in hierarchical tree view, and htop -s COLUMN sorts by the named column (run htop --sort-key=help to list all valid column names).
Along the bottom of the htop window, a persistent function-key legend maps common actions: F1 (Help), F2 (Setup meters/columns), F3 or / (Incremental search), F4 or \ (Live substring filter), F5 or t (Tree view toggle), F6 or > (Select sort column), F7/F8 (Decrease/Increase nice value), F9 or k (Kill/send signal), and F10 or q (Quit).
0— Successful execution with no runtime or permission errors.1— Operational failure, unmatched condition, or permission restriction.2— Invalid command-line option or malformed syntax.
Important Options and Flags Reference
| Option / Flag | Long Form / Argument | Technical Behavior and Purpose |
|---|---|---|
-d | --delay=DELAY | Sets the refresh delay interval in tenths of a second (e.g., -d 10 refreshes every 1.0 second; -d 50 refreshes every 5.0 seconds). |
-u | --user=USERNAME | Displays only processes owned by the specified username or numeric UID. |
-p | --pid=PID,PID... | Monitors only the specified comma-separated list of Process IDs. |
-s | --sort-key=COLUMN | Sorts the task table by the specified column (e.g., PERCENT_CPU, PERCENT_MEM, M_RESIDENT, TIME). |
-t | --tree | Starts htop in hierarchical process tree mode showing parent-child relationships. |
-H | --highlight-changes[=DELAY] | Highlights newly spawned processes in green and terminating processes in red for DELAY seconds. |
-M | --no-mouse | Disables mouse click and scroll wheel capture inside the terminal interface. |
-r | --readonly | Runs htop in read-only mode, disabling kill, renice, and strace actions for safe dashboard displays. |
Note the unit difference for the -d flag between top and htop: while top -d 1 sets a 1-second delay, htop -d measures time in tenths of a second (deciseconds). Thus, to refresh htop every 1 second, run htop -d 10.
Inside interactive htop, two of the most powerful lesser-known hotkeys are s (which spawns strace -p PID in a live scrollable pane for the selected process) and l (which runs lsof -p PID to show every file descriptor, log file, and network socket the selected process has open).
When combining short flags on the command line, POSIX and GNU utilities allow clustering boolean flags behind a single hyphen, provided any option taking an argument appears last. In automated shell scripts, using long-form GNU options where portable makes self-documenting code that is easier to audit during peer review.
Practical Basic and Advanced Usage Examples
1. Install and Launch htop Sorted by Memory Usage
Check available sort keys with htop --sort-key=help and launch htop pre-sorted by resident memory percentage.
htop --sort-key=help | head -n 8
htop --sort-key=PERCENT_MEM
# Illustrative output (reviewed against documentation)
Command Command
ElapsedTime Time+
IO_PASSIVE IO
M_RESIDENT RES
M_SHARE SHR
M_SIZE VIRT
PERCENT_CPU CPU%
PERCENT_MEM MEM%
Starting htop with --sort-key=PERCENT_MEM (or pressing M inside htop) immediately places the largest RAM consumers at the top of the viewport.
2. Open htop Directly in Hierarchical Process Tree View (-t)
Pass -t (--tree) on startup or press F5 (or t) interactively to visualize how systemd and master daemons fork child worker processes.
htop -t
# Illustrative output (reviewed against documentation)
# Launches interactive htop with tree branches (├─ and └─) expanded under PID 1
While in tree mode, you can press + or - on any parent process to collapse or expand its child worker subtree.
3. Monitor Only Processes Belonging to a Specific User (-u)
Scope the htop process list to a single application account such as postgres or www-data.
htop -u postgres
# Illustrative output (reviewed against documentation)
# Displays per-core CPU/Memory meters at top and only postgres-owned processes below
You can also switch users dynamically inside htop by pressing u and selecting an account from the interactive sidebar list.
4. Watch a Specific Set of PIDs and Highlight New/Dying Processes (-p -H)
Combine -p with pidof and -H (--highlight-changes) to watch a service's workers and visually highlight newly spawned or exiting tasks.
htop -p "$(pidof -d ',' nginx)" -H 5
# Illustrative output (reviewed against documentation)
# Launches htop tracking only nginx PIDs; new workers highlight green for 5 seconds
The -H flag is especially useful for diagnosing crash-looping services or short-lived worker processes that vanish between refreshes.
5. Toggle Kernel Threads and User Threads Visibility (K and H)
By default, htop displays user-space threads (LWP) alongside processes. Press H to hide user threads so only main processes appear, or K to hide kernel threads.
# Inside interactive htop:
# Press Shift+H to toggle user threads on/off
# Press Shift+K to toggle kernel threads on/off
# Illustrative output (reviewed against documentation)
# Collapses multi-threaded Java/MySQL/Node.js thread rows into a single parent PID row
Many administrators are surprised to see 40 identical rows for one Java or Python application in htop; pressing Shift+H collapses those user-space threads into a single process row matching ps.
6. Run htop in Safe Read-Only Mode for NOC Wallboards (-r)
Launch htop with --readonly (-r) and a 2-second refresh interval (-d 20) so nobody can accidentally kill or renice processes from a shared monitoring terminal.
htop --readonly -d 20
# Illustrative output (reviewed against documentation)
# Launches htop with F7/F8 (nice) and F9 (kill) disabled
Read-only mode disables all state-changing actions while preserving full sorting, filtering, and tree-browsing capabilities.
Real-World Workflows, Pipelines, and Shell Automation
Tagging and Batch-Killing Multiple Runaway Processes Interactively
When dozens of stuck worker processes need to be terminated without writing a regex, filter the view with F4, tag processes with Space, and signal all tagged processes at once with F9.
# Interactive htop batch workflow:
# 1. Run: sudo htop
# 2. Press F4 (Filter) and type: sync_worker
# 3. Highlight target processes and press Spacebar to tag them (turns yellow)
# (Or press 'c' to tag the highlighted parent process and all its children!)
# 4. Press F9 (Kill), choose 15 SIGTERM, and press Enter
# Illustrative output (reviewed against documentation)
# Sends SIGTERM simultaneously to every tagged process in the selection group
Pressing 'c' on a parent process inside htop tags both the parent and every descendant child process in its tree—making it trivial to terminate an entire hung job hierarchy safely.
Deploy a Standardized Team htoprc Configuration with I/O and PSI Meters
Pre-configure ~/.config/htop/htoprc on new servers via dotfiles or Ansible so user threads are hidden by default and CPU/Memory Pressure Stall Information (PSI) meters are visible.
mkdir -p ~/.config/htop
cat << 'EOF' > ~/.config/htop/htoprc
hide_kernel_threads=1
hide_userland_threads=1
shadow_other_users=0
show_thread_names=1
show_program_path=1
highlight_base_name=1
highlight_megabytes=1
tree_view=0
header_margin=1
detailed_cpu_time=1
EOF
echo "Configured ~/.config/htop/htoprc with clean process defaults."
# Illustrative output (reviewed against documentation)
Configured ~/.config/htop/htoprc with clean process defaults.
Setting hide_userland_threads=1 and highlight_base_name=1 in htoprc makes htop immediately readable on servers running heavily multi-threaded workloads.
Pipelines, Redirection, Quoting, and Shell Expansion
When embedding htop inside shell pipelines (|), conditional chains (&& and ||), or command substitutions ($(...)), the calling shell performs tilde expansion, variable interpolation, and globbing before invoking the binary. Always wrap paths, patterns, and variables in quotes so whitespace and wildcard characters (*, ?) are not expanded prematurely, and use set -euo pipefail in unattended scripts.
Permissions, Security Implications, and Safe Execution
Pressing F9 inside sudo htop can immediately send SIGKILL (9) or SIGTERM (15) to the highlighted or tagged processes. If any processes are tagged in yellow with the Spacebar, F9 applies to ALL tagged processes rather than the single row under your cursor.
When run as an unprivileged user, htop can display standard CPU and memory metrics for processes visible in /proc, but inspecting per-process disk I/O columns (RBYTES, WBYTES, IO_RATE), open file descriptors (l / lsof), or system calls (s / strace) for root-owned services requires running sudo htop.
On shared bastion hosts, prefer launching htop --readonly so accidental keystrokes cannot send termination signals to active sessions.
GNU/Linux, BSD, and BusyBox Implementation Differences
Unlike top (which is pre-installed in base OS images via procps-ng), htop is an optional package on RHEL/Rocky/AlmaLinux (requiring the EPEL repository on some releases via sudo dnf install epel-release && sudo dnf install htop) and minimal Debian/Alpine containers.
htop 3.x runs natively across Linux, FreeBSD, OpenBSD, NetBSD, Solaris, and macOS (via Homebrew).
Troubleshooting Common Errors and Diagnostics
htop shows dozens of duplicate entries with identical memory usage for one application
Root Cause: By default, htop displays every individual user-space thread (LWP) as its own line, and each thread shares the parent process's RES and VIRT memory counters.
Resolution: Press uppercase H (Shift+H) inside htop to hide userland threads so only one row per process is displayed.
# Press Shift+H inside htop, then press F10 to save to ~/.config/htop/htoprc
Function keys (F1–F10) are intercepted by the local terminal emulator (e.g., F10 opens terminal menu)
Root Cause: Desktop terminal emulators (GNOME Terminal, XFCE Terminal, macOS Terminal) often bind F1, F10, or F11 to window menus or full-screen toggles.
Resolution: Use htop's built-in single-letter equivalents instead of function keys: '?' for F1 (Help), 'S' for F2 (Setup), '/' for F3 (Search), '\' for F4 (Filter), 't' for F5 (Tree), '>' for F6 (Sort), 'k' for F9 (Kill), and 'q' for F10 (Quit).
# Single-key equivalents: ? (Help), S (Setup), / (Search), \ (Filter), t (Tree), k (Kill), q (Quit)
No package htop available on RHEL / Rocky Linux / AlmaLinux
Root Cause: On Enterprise Linux distributions, htop is hosted in the Extra Packages for Enterprise Linux (EPEL) repository rather than BaseOS.
Resolution: Enable epel-release first and then install htop with dnf.
sudo dnf install -y epel-release
sudo dnf install -y htop
Alternatives, Related Commands, and Related Tutorials
- top Command in Linux: Monitor CPU, Memory, and Processes in Real Time — Practical syntax, flags, and examples for
top. - btop Command in Linux: Modern Terminal Resource Monitor — Practical syntax, flags, and examples for
btop. - ps Command in Linux: ps aux, ps -ef, Custom Columns, and Sorting — Practical syntax, flags, and examples for
ps. - How to Kill a Process in Linux: kill, killall, and pkill Guide — Practical syntax, flags, and examples for
kill. - 25 Best Linux Commands Every Sysadmin Should Know — Core command-line utilities for daily Linux server administration.
- How to Find a File in Linux from the Command Line — Practical file search patterns across Linux directories.
- Linux Commands Knowledge Hub (#linux-commands) — Browse all Linux command-line tutorials and system administration references.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides



Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!