keepcalculator

06 Numbers and Powers

Power User Guide htop: Master Linux Process Management

Card No. 06·4948 · Updated · Standard formula, shown below

This guide explains how to use htop as a power user, covering interactive commands, sorting, filtering, tree view, and customization. You will learn to read every column, manage processes efficiently, and troubleshoot system performance issues directly from the terminal.

What htop Is and Why It Matters

htop is an interactive process viewer and manager for Unix-like systems, built as an improved alternative to the traditional top command. It provides a real-time, color-coded display of system resources—CPU, memory, and swap—alongside a detailed list of running processes. Unlike top, htop lets you scroll vertically and horizontally, send signals (like SIGKILL or SIGTERM) without typing PIDs, and manage processes using function keys or mouse clicks. For system administrators, developers, and anyone who spends time in a terminal, htop is an indispensable tool for monitoring system health and diagnosing performance bottlenecks.

Installation and Basic Launch

htop is not installed by default on most distributions, but it is available in official repositories. Install it using your package manager:

  • Debian/Ubuntu: sudo apt install htop
  • RHEL/CentOS/Fedora: sudo dnf install htop (or yum on older versions)
  • Arch Linux: sudo pacman -S htop
  • macOS (via Homebrew): brew install htop

Launch htop by typing htop in a terminal. You will see a header with meters for CPU, memory, and swap, a list of processes, and a footer with function key hints. The default refresh interval is 1 second; you can change it with the -d flag (e.g., htop -d 5 for 5 seconds).

Reading the Interface: Meters and Columns

The top section shows multiple meters. Each CPU meter is labeled with a number (e.g., 1, 2) or a percentage. The color coding is consistent: green for user processes, red for system (kernel) processes, blue for low-priority (nice) processes, and yellow for IRQ time. Memory and swap meters show used and cached amounts.

The process list contains several columns. The most important ones:

  • PID: Process ID.
  • USER: Owner of the process.
  • PRI: Kernel’s priority (higher number = lower priority).
  • NI: Nice value (affects priority; -20 to 19).
  • VIRT: Total virtual memory allocated (includes swapped and mapped libraries).
  • RES: Resident memory (physical RAM used, excluding swap).
  • SHR: Shared memory (e.g., shared libraries).
  • S: Process state (R running, S sleeping, D uninterruptible sleep, Z zombie, T stopped).
  • CPU%: Percentage of CPU time used by the process.
  • MEM%: Percentage of physical memory used.
  • TIME+: Cumulative CPU time consumed (hours:minutes:seconds).
  • Command: The command line that launched the process.

Interactive Controls: Keys and Shortcuts

htop is fully keyboard-driven. Here are the essential keys every power user should know:

  • F1 / h: Help screen.
  • F2 / S: Setup (configuration menu).
  • F3 / /: Search for a process by name (type a string, press Enter).
  • F4 / \: Filter processes by name (type a substring, only matching processes show).
  • F5 / t: Toggle tree view (shows parent-child relationships).
  • F6 / >: Sort by a column (select with arrow keys, Enter to apply).
  • F7 / ]: Decrease nice value (increase priority) of selected process (requires root).
  • F8 / [: Increase nice value (decrease priority).
  • F9 / k: Send a signal to the selected process (choose from list, e.g., SIGTERM, SIGKILL).
  • F10 / q: Quit htop.
  • Space: Tag/un-tag a process (for multiple signal sending).
  • u: Show only processes of a specific user.
  • p: Toggle full command path vs. program name.
  • H: Toggle display of user threads.
  • K: Toggle display of kernel threads.
  • F: Toggle follow process (keeps selected process in view).
  • + / –: Expand/collapse tree nodes (in tree view).

Sorting, Filtering, and Searching

Sorting is crucial for finding resource hogs. Press F6 to open the sort column menu, select CPU% or MEM% with arrow keys, and press Enter. The list will reorder instantly. To sort by a different column without the menu, use < and > to cycle through columns.

Filtering (F4) is useful when you want to see only processes matching a pattern (e.g., nginx). The filter is case-sensitive and matches against the command line. To clear a filter, press F4 again and delete the text.

Search (F3) jumps to the next occurrence of a string in the process list. It is handy for finding a specific PID or command quickly.

Customizing htop with Setup (F2)

Press F2 to open the setup screen. Here you can:

  • Add or remove meters (CPU, Memory, Swap, etc.) and change their display style (bar, text, graph).
  • Choose which columns to display and their order (e.g., add PPID, start time, or I/O rates).
  • Set display options like tree view by default, hide user threads, or show custom program name.
  • Change colors (if your terminal supports 256 colors).

All changes are saved to ~/.config/htop/htoprc (or ~/.htoprc on older versions). You can edit this file manually for fine-grained control, but the setup menu covers most needs.

Managing Processes: Signals and Killing

To terminate a process, select it and press F9. A menu appears with a list of signals. The most common are:

  • SIGTERM (15): Graceful termination—allows the process to clean up.
  • SIGKILL (9): Force kill—cannot be caught or ignored.
  • SIGSTOP (19): Pause the process.
  • SIGCONT (18): Resume a paused process.

You can also send signals to multiple processes at once by tagging them with Space and then pressing F9. This is powerful for batch operations, like killing all leftover chrome processes.

Changing priority (nice value) is done with F7/F8. A lower nice value (e.g., -5) gives the process higher priority. Only root can decrease nice values below 0.

Tree View and Threads

Tree view (F5) displays processes in a hierarchical structure, showing which process spawned which. This is invaluable for understanding dependency chains and spotting orphaned processes. Use the + and - keys to expand/collapse branches, and arrow keys to navigate.

By default, htop shows only process threads that are not kernel threads. Press H to toggle user threads (each thread appears as a separate entry) and K to show kernel threads. This can help identify thread-level CPU usage, but it can also clutter the view.

Monitoring System Health and Troubleshooting

htop is not just for killing processes; it is a real-time health monitor. The CPU meters show per-core usage; if one core is at 100% while others are idle, you may have a single-threaded bottleneck. Memory pressure shows in the Mem meter: if ‘used’ is high and ‘cached’ is low, you might need more RAM. Swap usage indicates memory pressure—if swap is actively used, the system is swapping, which degrades performance.

For network I/O, htop does not show per-process network usage by default (you need nethogs or iftop for that). However, you can add a ‘Network’ meter in setup, but it shows total system I/O, not per-process.

Common Problems and Misconceptions

One common issue is that htop does not show the same CPU% as top because htop normalizes CPU% across all cores by default. In htop, a single-threaded process using one core on a 4-core system shows 100% CPU, while top might show 25% (depending on configuration). This is not a bug—it’s a design choice. You can change this in Setup under ‘CPU%’ display to ‘per-core’ or ‘average’.

Another misconception: killing a process with SIGKILL is always safe. It is not—it can leave files corrupted or locks held. Always try SIGTERM first and give the process a few seconds to exit.

Alternatives and Comparisons

htop is not the only process manager. Alternatives include:

  • top: Simpler, available everywhere, but less interactive.
  • bpytop / btop: More modern, with graphical meters and mouse support, but heavier.
  • glances: Web-based and CLI, shows system info across many categories.
  • ps: Static snapshot, not interactive.

For most users, htop strikes the best balance between features and simplicity. It is lightweight, fast, and available on virtually every Linux distribution.

Frequently Asked Questions

How do I kill a process in htop?

Select the process with arrow keys, press F9, choose SIGTERM (or SIGKILL if it doesn’t respond), and press Enter. For multiple processes, tag them with Space and then press F9.

Why does htop show different CPU% than top?

By default, htop shows CPU% as a percentage of a single core, while top shows it as a percentage of total CPU capacity. On a multi-core system, a process using one full core will show 100% in htop but 25% in top (on a 4-core system). You can change htop’s behavior in Setup.

Can I use htop to see network usage per process?

No, htop does not provide per-process network I/O. For that, use tools like nethogs or iftop. htop’s network meter shows total system bandwidth only.

How do I save my htop configuration?

Press F2 to enter Setup, make your changes, and press F10 to exit. The configuration is automatically saved to ~/.config/htop/htoprc.

Is htop safe to use on production servers?

Yes, htop is a read-only monitor by default. It only changes system state when you explicitly send a signal or change priority. It is safe to run on any server.

How do I sort processes by memory usage in htop?

Press F6, select MEM% with the arrow keys, and press Enter. Alternatively, press > repeatedly until the MEM% column is highlighted.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →