Monitoring system performance is crucial for every Linux user, especially system administrators and developers. One of the best tools for real-time system monitoring is htop on Linux. Unlike the traditional top
command, htop provides a user-friendly interface, color-coded resource usage graphs, and interactive process management.
In this guide, we’ll explore how to install and use htop on Linux, break down its interface, and demonstrate real-world scenarios, including simulating high CPU and memory usage.
📌 For a step-by-step visual guide, watch this video:
What is htop on Linux?
htop is an interactive system-monitoring tool that serves as an enhanced alternative to the top
command. It provides detailed insights into system performance, making it easier to manage running processes and troubleshoot performance issues.
Key Features of htop on Linux
✅ Graphical Representation – Displays CPU, memory, and swap usage with color-coded bars.
✅ Process Management – Navigate, search, and kill processes interactively.
✅ Sorting & Filtering – Sort by CPU, memory, or user and filter processes quickly.
✅ Customizable Interface – Modify displayed columns to include disk I/O, network stats, and more.
Installing htop on Linux
Before using htop on Linux, ensure it is installed by running:
Once installed, launch it with:
Understanding htop on Linux: Interface Breakdown
When you open htop on Linux, you’ll see three primary sections:
1️⃣ Header Section – System Resource Usage
Displays CPU, memory, and swap usage with color-coded bars:
🔹 Green – Regular user processes
🔹 Blue – Low-priority processes
🔹 Red – Kernel threads or high-resource-consuming tasks
🔹 Orange (Memory) – Cached memory
2️⃣ Process List – Running Processes
Displays active processes with columns like PID, user, priority, CPU usage, and memory usage.
Contains function key shortcuts for sorting, searching, and managing processes interactively.
Practical Use Cases of htop on Linux
1️⃣ Simulating High CPU and Memory Usage
🔹 Scenario: Your server is lagging, and you suspect high CPU or memory usage. Instead of waiting for a real issue, let’s simulate one using the stress
tool.
✅ Step 1: Install stress
✅ Step 2: Simulate CPU Load
Run the following command to generate 4 CPU-intensive tasks for 60 seconds:
Now, open htop on Linux in another terminal:
You’ll notice CPU usage spiking with red bars indicating high utilization.
✅ Step 3: Simulate High Memory Usage
This command creates 2 memory-intensive tasks, each consuming 500MB. Observe memory usage in htop.
✅ Step 4: Terminating Stress Processes
To manually stop the stress test, use:
2️⃣ Filtering Specific Processes
🔹 Scenario: You need to troubleshoot an issue with Apache (httpd
), but the process list is too crowded.
🔹 Solution: Press F4
, type httpd
, and only Apache-related processes will be shown.
3️⃣ Monitoring User-Specific Processes
🔹 Scenario: You want to check which processes a specific user is running.
🔹 Solution: Run:
In my case, since I don’t have a developer
user, I will use:
4️⃣ Tree View for Process Hierarchy
🔹 Scenario: You need to analyze how processes are started, which is useful for debugging services and dependencies.
🔹 Solution: Press F5
to switch to tree view mode in htop on Linux.
5️⃣ Killing Unresponsive Processes
🔹 Scenario: A database query is stuck, and PostgreSQL is consuming excessive CPU.
🔹 Solution: Locate the process in htop, select it with arrow keys, and press F9 to kill it.
6️⃣ Displaying Only Active Processes
🔹 Scenario: You want to focus on active tasks and hide idle ones.
🔹 Solution:
- Press
F2
(Setup) → Go to Display Options - Enable “Hide kernel threads” and “Hide idle processes”
Customizing htop on Linux for Better Insights
Want more details? Customize htop on Linux to display additional system metrics like disk I/O and network activity.
Steps to Customize htop:
✅ Press F2
(Setup) → Navigate to Columns
✅ Add:
- IO Read/Write for disk performance
- Threads to monitor multi-threaded applications
✅ PressF10
to save and exit
FAQs About htop on Linux
1. How is htop different from top?
✅ htop is interactive, color-coded, and allows process navigation, sorting, and filtering, unlike the traditional top
command.
2. How do I install htop on different Linux distributions?
- RHEL-based (Rocky Linux, AlmaLinux, CentOS):
sudo dnf install htop -y
- Debian-based (Ubuntu, Debian):
sudo apt install htop -y
3. How can I monitor specific user processes in htop?
Use the command:
Replace username
with the actual user.
4. Can I customize the columns in htop?
Yes! Press F2
(Setup), navigate to Columns, and add or remove fields.
5. How do I sort processes by CPU or memory usage?
Press F6
, then select CPU% or MEM% to sort processes accordingly.
Conclusion
By mastering htop on Linux, you gain powerful system-monitoring capabilities. From analyzing CPU and memory usage to filtering processes and troubleshooting performance issues, htop is an essential tool for Linux administrators and developers.
For a step-by-step visual guide, check out this video.