Table of Contents#
- Installation
- Interface Overview
- Key Features of Htop
- Navigation and Shortcuts
- Customizing Htop
- Advanced Usage
- Practical Examples
- Conclusion
- References
Installation#
Htop is pre-installed on many Linux distributions, but if it’s not on your system, installing it is straightforward. Below are commands for popular Linux distros:
Debian/Ubuntu/Linux Mint#
sudo apt update && sudo apt install htop -y RHEL/CentOS/Rocky Linux#
On RHEL-based systems, Htop is available in the EPEL (Extra Packages for Enterprise Linux) repository. First, enable EPEL, then install:
sudo dnf install epel-release -y
sudo dnf install htop -y Fedora#
Fedora includes Htop in its default repositories:
sudo dnf install htop -y Arch Linux/Manjaro#
sudo pacman -S htop macOS (via Homebrew)#
While Htop is Linux-focused, macOS users can install it via Homebrew:
brew install htop Once installed, launch Htop by simply typing htop in the terminal:
htop Interface Overview#
When you first launch Htop, you’ll see a dynamic, color-coded interface divided into three main sections:
1. Header (System Summary)#
The top portion of the screen displays real-time system metrics:
- CPU Usage: A horizontal bar graph showing usage per CPU core (or total CPU). Colors indicate usage types:
- Blue: Low-priority (nice) processes.
- Green: Normal user processes.
- Red: Kernel processes.
- Yellow: I/O wait (disk/network bottlenecks).
- Memory Usage: Two bars for physical memory (RAM) and swap space.
- Green: Used memory.
- Blue: Buffers (temporary data for I/O).
- Yellow: Cache (frequently accessed data).
- Load Average: Three numbers (e.g.,
0.85 0.92 0.78) representing system load over 1, 5, and 15 minutes. - Uptime: How long the system has been running (e.g.,
1d 2h 30m).
2. Process List#
The middle section lists all running processes in a tabular format. Key columns include:
- PID: Process ID (unique identifier).
- USER: User running the process.
- PR: Priority (higher = more CPU time;
rt= real-time priority). - NI: “Nice” value (adjusts priority; ranges from -20 (highest) to 19 (lowest)).
- VIRT: Total virtual memory used (includes swapped memory).
- RES: Resident set size (physical memory used, not swapped).
- SHR: Shared memory (memory shared with other processes).
- S: Process status (e.g.,
R= running,S= sleeping,D= disk sleep,Z= zombie,T= stopped). - %CPU: CPU usage percentage.
- %MEM: Memory usage percentage.
- TIME+: Total CPU time consumed (e.g.,
0:05.23= 5 seconds). - COMMAND: The command that started the process.
3. Status Bar (Footer)#
The bottom bar displays keyboard shortcuts for common actions (e.g., F1 for help, F9 to kill a process).
Key Features of Htop#
Htop’s popularity stems from its rich feature set, which addresses many limitations of top:
1. Interactive Interface#
Unlike top, Htop supports mouse interactions (click to select processes, resize columns, or use buttons). You can also scroll horizontally/vertically to view all processes or columns, even on small terminals.
2. Color-Coding#
Colors make it easy to distinguish between process types, resource usage, and statuses. For example:
- Red
%CPUindicates a process consuming significant CPU. - Zombie processes (
Zstatus) are highlighted in red.
3. Tree View#
Press F5 to toggle tree view, which shows parent-child process relationships (e.g., how a service like systemd spawns child processes). This is invaluable for understanding process hierarchies.
4. Process Filtering and Search#
- Search: Press
F3to search for a process by name (e.g.,nginx). - Filter: Press
F4to filter processes by a keyword (e.g., show onlypythonprocesses).
5. One-Click Process Management#
Kill or send signals to processes without memorizing PIDs:
- Select a process with arrow keys.
- Press
F9to send a signal (e.g.,SIGTERM(15) to terminate gracefully,SIGKILL(9) to force kill).
6. Customizable Columns#
Add/remove columns (e.g., PPID for parent PID, CPU for core ID) via the setup menu (F2).
7. Real-Time Updates#
By default, Htop refreshes every 1 second, but you can adjust this interval in the setup menu.
Navigation and Shortcuts#
Htop’s power lies in its keyboard shortcuts. Here’s a cheat sheet of the most useful ones:
| Shortcut | Action | Description |
|---|---|---|
F1 or h | Help | Show all shortcuts. |
F2 or S | Setup | Customize interface (columns, colors, meters). |
F3 or / | Search | Search for a process by name (case-insensitive). |
F4 or \ | Filter | Filter processes by a keyword (e.g., java). |
F5 or t | Tree View | Toggle parent-child process tree. |
F6 or > | Sort By | Choose a column to sort processes (e.g., %CPU, %MEM). |
F7 or - | Decrease Nice Value | Increase process priority (lower NI = higher priority). |
F8 or + | Increase Nice Value | Decrease process priority (higher NI = lower priority). |
F9 or k | Kill Process | Send a signal to terminate a process (e.g., SIGKILL). |
F10 or q | Quit | Exit Htop. |
Space | Tag Process | Tag multiple processes (e.g., to kill them all at once). |
u | Filter by User | Show processes for a specific user. |
p | Filter by PID | Show processes with specific PIDs. |
Shift + H | Hide Threads | Toggle visibility of threads (default: shown). |
Shift + P | Sort by CPU Usage | Quickly sort processes by %CPU (descending). |
Shift + M | Sort by Memory Usage | Quickly sort processes by %MEM (descending). |
Customizing Htop#
Htop is highly customizable via the Setup menu (F2). Here’s how to tailor it to your workflow:
1. Meters (Header Customization)#
In the Setup menu, navigate to Meters to adjust the system summary in the header:
- Add/remove meters (e.g., CPU cores, memory, swap, load average).
- Change meter style (bar, text, histogram).
- Adjust colors for CPU/memory usage.
2. Columns (Process List Customization)#
Go to Columns to modify the process table:
- Add columns (e.g.,
PPID(parent PID),WCHAN(wait channel),STIME(start time)). - Remove unnecessary columns (e.g.,
SHRif not needed). - Reorder columns by selecting and using arrow keys.
3. Display Options#
Tweak how Htop looks:
- Update Interval: Change how often Htop refreshes (default: 1 second).
- Delay Time: Adjust the refresh delay (in tenths of a second).
- Hide Idle Processes: Toggle visibility of processes with 0% CPU/memory usage.
4. Colors#
Customize color schemes for different elements (e.g., CPU usage, process statuses). Choose from predefined themes or create your own.
Advanced Usage#
Beyond basic navigation, Htop offers advanced features for power users:
Command-Line Options#
Launch Htop with flags to customize its behavior on startup:
-d <seconds>: Set refresh interval (e.g.,htop -d 2for 2-second updates).-u <user>: Show only processes for a user (e.g.,htop -u john).-p <pid1,pid2>: Monitor specific PIDs (e.g.,htop -p 1234,5678).-s <column>: Sort by a column on startup (e.g.,htop -s PERCENT_CPU).--no-color: Disable color (useful for monochrome terminals).
Batch Mode#
For scripting or logging, use Htop in non-interactive (batch) mode with -b:
htop -b -n 1 > htop_snapshot.txt # Capture 1 snapshot and save to file Integrating with Other Tools#
Pipe Htop output to tools like grep for advanced filtering:
htop | grep python # Show only Python processes (alternative to F4 filter) Practical Examples#
Let’s walk through common scenarios where Htop shines:
Example 1: Identify a High-CPU Process#
- Launch Htop:
htop. - Press
Shift + Pto sort processes by%CPU(descending). - The top process is the CPU hog. Note its PID (e.g.,
1234). - To kill it: Select the process with arrow keys, press
F9, chooseSIGKILL(9), and pressEnter.
Example 2: Find Memory-Intensive Processes#
- Launch Htop:
htop. - Press
Shift + Mto sort by%MEM. - Identify processes using the most RAM (e.g., a misbehaving
chrometab). - Tag multiple processes with
Space, then pressF9to kill them all.
Example 3: Analyze Process Hierarchies#
- Press
F5to enable tree view. - Expand/collapse process trees with
Enterto see parent-child relationships (e.g., which service spawned a problematic process).
Example 4: Filter Processes by User#
- Press
u, then type a username (e.g.,root), and pressEnter. - Htop will show only processes owned by
root.
Conclusion#
Htop is more than just a process viewer—it’s a powerful tool that simplifies system monitoring and process management for Linux users. With its interactive interface, color-coded metrics, and extensive customization options, it outperforms the traditional top command in usability and functionality. Whether you’re troubleshooting a slow system, managing resources, or simply keeping an eye on processes, Htop is an essential addition to your Linux toolkit.
Give it a try today—you’ll wonder how you ever managed without it!