Website Vidya
Linux & ServersStep-by-Step Guide

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.

RR
Rajesh RayLead Systems Educator
Published:
10 min read
PDF Cheat Sheet
htop Command in Linux: Interactive Process Viewer and Manager
AI Executive SummaryWebsiteVidya AI

10 min read

Learn htop command in linux with syntax, essential flags, practical terminal examples, real-world sysadmin workflows, security tips, and troubleshooting.

Key Highlights
  • What htop Does and When to Use It
  • Availability and Installation Across Linux Distributions
  • Command Syntax, Arguments, and Exit Status Codes
Grounded in full engineering runbookWebsiteVidya AI Engine

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.

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.

Advertisement
htop Command in Linux: Interactive Process Viewer and Manager — syntax, flags, and practical terminal workflow diagram
htop Command in Linux: Interactive Process Viewer and Manager — command syntax, key options, and production workflow reference.

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:

Advertisement

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 / FlagLong Form / ArgumentTechnical Behavior and Purpose
-d--delay=DELAYSets 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=USERNAMEDisplays 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=COLUMNSorts the task table by the specified column (e.g., PERCENT_CPU, PERCENT_MEM, M_RESIDENT, TIME).
-t--treeStarts 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-mouseDisables mouse click and scroll wheel capture inside the terminal interface.
-r--readonlyRuns 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.

Advertisement

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

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

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
In the CPU meter: Green is normal user processes, Blue is low-priority (niced) processes, Red is kernel/system time, and Cyan/Grey is I/O wait or hypervisor steal time (when detailed CPU time is enabled). In the Memory meter: Green is used process memory, Blue is buffers, and Yellow/Orange is filesystem cache.
htop's green Memory bar shows only memory actively used by processes (excluding reclaimable kernel buffers and page cache, which are colored blue and yellow). You can see the exact breakdown inside the meter text.
Press F4 (or backslash \) and type a substring to filter the list so only matching processes remain visible. Press F3 (or forward slash /) to jump the cursor to the next matching process without hiding other rows.
Highlight the target process with the arrow keys and press 's' to open a live strace system-call view, or press 'l' to view all open files and network sockets via lsof.
RR
Written byVerified Author

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.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout