>_cmd.script

htop

Interactive, colorized process viewer with tree view and mouse support

Processes

By CMD Script Team · 4 min read · Last updated

SYNTAX
htop [OPTIONS]

Options

Command options and flags
FlagDescription
-uShow only processes owned by a given user, e.g. -u alice
-pMonitor only specific PIDs, e.g. -p 1234,5678
-dSet the update delay in tenths of a second, e.g. -d 10 for 1 second
-CDisable color output (useful over limited terminals or for logging)
-tStart with tree view enabled, showing parent/child process hierarchy
-sSort by a given column at startup, e.g. -s PERCENT_CPU

Distribution compatibility

  • Ubuntu
  • Debian
  • Fedora
  • Arch
  • macOS (install via Homebrew: brew install htop)

What it does

htop is an interactive process viewer, similar to top but built for readability and ease of use: it shows colorized per-core CPU meters and a memory/swap bar graph at the top, a scrollable process list below, and supports the mouse for selecting, sorting, and acting on processes. It's not part of core Unix tooling — it's a third-party tool (originally written in C using ncurses) that's become a near-universal install on developer machines and servers because it removes a lot of the friction top has around navigation and process actions.

Beginner examples

  • htop — launch the interactive view
  • Use arrow keys or the mouse to scroll and select a process
  • Press F10 or q to quit
  • Press F6 (or </>) to change the sort column, e.g. switch to CPU% or memory%
htop

Advanced examples

  • Start already filtered to one user: htop -u alice
  • Start in process-tree view to see parent/child relationships immediately: htop -t
  • Pin the view to specific PIDs you care about, ignoring everything else: htop -p 1234,5678
  • Sort by memory usage from launch instead of the default CPU sort: htop -s PERCENT_MEM
  • Run with color disabled, e.g. when logging or piping through a limited terminal: htop -C
htop -u www-data -t

Common mistakes

  • Assuming htop is preinstalled everywhere — many minimal server and container images ship only top, so scripts and runbooks that assume htop exists can fail on fresh hosts; install it explicitly (apt install htop / dnf install htop) as a prerequisite.
  • Not knowing the function-key shortcuts and trying to type commands like in top — in htop, F9/k kills, F7/F8 renice down/up, and F5/t toggles tree view, mostly navigated by highlighting a row first.
  • Confusing the per-core CPU bars at the top with per-process CPU% in the list below — the bars are an aggregate system view, the list rows are per-process.
  • Forgetting that, like top, htop's %CPU for a process can exceed 100% on multi-core systems when a process uses more than one core.

Tips

  • Press F5 (or t) to toggle tree view — extremely useful for spotting which parent process spawned a runaway child, especially with shell scripts or containerized apps.
  • Press F4 to filter the list by typing a search string, narrowing to matching process names live as you type.
  • Press Space to "tag" multiple processes, then act on all of them at once (e.g. kill several at a time) instead of one by one.
  • Use the mouse to click column headers to sort, or click directly on a process to select it — htop is one of the few classic terminal tools with full mouse support out of the box.

Best practices

  • Install htop as part of your standard server provisioning/base image if your team relies on it for triage, rather than discovering it's missing during an incident.
  • Use tree view (F5/t) whenever diagnosing a misbehaving service made of multiple processes, so you can see the whole process family rather than a flat, hard-to-relate list.
  • Prefer tagging (Space) and batch-acting over repeatedly killing processes one at a time when cleaning up several related runaway processes.
  • For non-interactive/scripted contexts (cron jobs, logging), use top -b or ps instead — htop is designed for interactive terminal use, not batch output.

Try it yourself

A simulated shell with a sample home directory — experiment freely, nothing leaves your browser. Type help to list supported commands.

Real-world use cases

  • Investigating a server slowdown interactively, using the color-coded CPU/memory bars to spot saturation at a glance before drilling into individual processes.
  • Killing a group of orphaned worker processes at once by tagging them with Space and hitting F9, rather than looking up and killing each PID individually.
  • Understanding a complex multi-process application's structure (e.g. a web server with worker processes) via tree view to see which processes are children of the main daemon.

Common interview questions

  • What are the main differences between htop and top? htop adds color, mouse support, a visual per-core CPU/memory bar graph, an interactive tree view of process hierarchy, and function-key shortcuts for actions like kill/renice — top is more minimal, keyboard-only, and universally preinstalled while htop is a separate package.
  • How would you kill several related processes at once in htop? Tag each one with Space, then press F9 (kill) to send a signal to all tagged processes together.
  • Is htop guaranteed to be available on every Linux system? No — unlike top, htop is a third-party package not included by default on minimal installs, so it needs to be installed explicitly (e.g. apt install htop).

Frequently Asked Questions

How is htop different from top?

htop adds color, a full-screen bar-graph summary of per-core CPU and memory usage, mouse support, horizontal/vertical scrolling, a tree view of process parent/child relationships, and function-key shortcuts for common actions like kill and renice — all without needing to memorize as many keyboard commands as top.

How do I kill a process in htop?

Select it with the arrow keys (or click with the mouse), press F9 (or k), choose a signal from the list (SIGTERM is the default, SIGKILL is 9), and press Enter to confirm.

Does htop come preinstalled on Linux?

Not always — many minimal server images only include top. Install htop with sudo apt install htop on Debian/Ubuntu or sudo dnf install htop on Fedora.

How do I see the process tree in htop?

Press F5 (or t) to toggle tree view, which nests child processes under their parents instead of showing a flat list.

Cheat sheet

Download a quick-reference cheat sheet for htop.