What it is
An interactive process viewer that displays real-time system resource usage and process information, useful for monitoring system performance and managing running processes.
Installation
Linux
sudo apt update && sudo apt install htop
# or
sudo yum install htop
# or
sudo dnf install htop
macOS
brew install htop
Windows
htop is not natively available on Windows. You can use the Windows Subsystem for Linux (WSL) to install and run htop.
- Install WSL: Follow Microsoft’s official guide.
- Open your WSL distribution (e.g., Ubuntu).
- Install
htopwithin WSL:sudo apt update && sudo apt install htop
Core Concepts
- Process Tree:
htopdisplays processes in a tree-like structure, showing parent-child relationships, which helps in understanding process dependencies. - Resource Meters: At the top, visual meters display CPU usage per core, memory usage (RAM and Swap), and Load Average.
- Process List: The main area lists individual processes with details like PID, User, Priority, Nice value, Virtual and Resident memory, State, CPU%, and Command.
- Interactive Commands:
htopallows direct interaction with processes (killing, renicing) via keyboard shortcuts.
Commands / Usage
htop is primarily interactive. The following are common keyboard shortcuts and actions:
Navigating the Process List
- Up/Down Arrow Keys: Move selection up/down.
- Page Up/Page Down: Scroll up/down one page.
- Home/End: Jump to the top/bottom of the list.
- Left/Right Arrow Keys: Scroll the displayed columns horizontally.
](Close bracket): Collapse a process tree branch.[(Open bracket): Expand a process tree branch.
Sorting and Filtering
F6or>: Open the sort options menu. Select a column (e.g.,CPU%,MEM%) to sort by.\(Backslash): Enter filter mode. Type a string (e.g.,nginx,user:root) to show only matching processes. PressEscto clear the filter.u: Filter by user. Prompts for a username. PressEscto clear.F4or\: (Same as\) Enter filter mode.
Process Management
F2orS: Open the setup menu. Customize displayed columns, meters, and color schemes.F3or/: Search for a process by name. Type the name and pressEnter. PressF3again to find the next occurrence. PressEscto clear the search.F9ork: Kill a selected process. Prompts for a signal (default isSIGTERM). Common signals:SIGTERM(15): Graceful termination request.SIGKILL(9): Forceful termination.SIGINT(2): Interrupt from keyboard (like Ctrl+C).
F7or]: Decrease the priority (increase nice value) of the selected process.F8or[: Increase the priority (decrease nice value) of the selected process.
Display Options
F5ort: Toggle tree view on/off.F10orq: Quithtop.H: Hide/show user threads.K: Hide/show kernel threads.M: Sort by memory usage.P: Sort by CPU usage.T: Sort by time/runtime.F: Tag a process. Useful for applying actions to multiple processes.U: Untag all tagged processes.I: Invert sort order.l: Show open file descriptors for the selected process.s: Trace the system calls of the selected process (requiresstraceto be installed).f: Go to the filter input.a: Show process details (like arguments).e: Show environment variables for the selected process.
Setup Menu (F2 or S)
- Meters: Configure which resource meters are displayed at the top (CPU, Memory, Swap, Load Average, Network, Disk I/O).
- Display Options: Configure overall display behavior (Tree view, Hide userland threads, Color scheme).
- Columns: Add, remove, or reorder the columns displayed in the process list. Common columns include:
PID: Process ID.USER: Owner of the process.PRI: Priority.NI: Nice value.VIRT: Virtual memory size.RES: Resident memory size.SHR: Shared memory size.S: Process State (R: Running, S: Sleeping, D: Disk Sleep, Z: Zombie, T: Stopped/Traced).CPU%: Percentage of CPU time used.MEM%: Percentage of physical RAM used.TIME+: Total CPU time used by the process.COMMAND: The command that started the process.
Common Patterns
-
Quickly find and kill a runaway process:
- Run
htop. - Press
F6and selectCPU%. - Press
F3and type the name of the suspected process (e.g.,python). - Use arrow keys to select the process.
- Press
F9andEnterto sendSIGTERM. If it doesn’t stop, repeat withSIGKILL(type9thenEnter).
- Run
-
Check memory hogs:
- Run
htop. - Press
F6and selectMEM%. - Observe the processes at the top of the list.
- Run
-
View processes for a specific user:
- Run
htop. - Press
u. - Type the username (e.g.,
www-data) and pressEnter.
- Run
-
See if a specific service is running:
- Run
htop. - Press
\(backslash). - Type the service name (e.g.,
sshd) and pressEnter.
- Run
-
Monitor CPU usage per core:
- Run
htop. - Observe the CPU meters at the top, which show usage for each CPU core individually.
- Run
Gotchas
- Permissions: To kill or renice processes owned by other users (especially
root), you’ll need to runhtopas root (sudo htop). SIGKILLis brutal:SIGKILL(signal 9) cannot be caught or ignored by a process. Use it as a last resort, as it prevents the process from cleaning up properly, potentially leading to data corruption.- Threads vs. Processes: By default,
htopoften shows individual threads. You can toggle thread visibility with theHkey (Hide/show user threads) to simplify the view if needed. - Interpreting Process States:
R(Running): The process is currently executing on a CPU or is ready to run.S(Sleeping): The process is waiting for an event (e.g., I/O completion, a signal). This is the most common state for idle processes.D(Uninterruptible Sleep): The process is waiting for I/O, often disk I/O. It cannot be killed easily, and if it hangs here, it might indicate a hardware or driver issue.Z(Zombie): The process has terminated, but its parent process hasn’t yet collected its exit status. Usually harmless and short-lived, but a persistent zombie can indicate a problem with the parent process.T(Stopped/Traced): The process has been stopped, usually by a signal (likeSIGSTOP) or while being debugged.
- Resource Usage Fluctuations: CPU and Memory percentages are snapshots in time. For sustained usage, observe trends over a few seconds or minutes. High CPU usage isn’t always bad; it might indicate the process is doing exactly what it’s supposed to. High idle CPU usage or consistently high memory usage for processes you don’t expect can be problematic.