Mastering htop on Linux: A Complete Guide to Monitoring System Performance

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:

sudo dnf install htop -y   # For RHEL-based distributions like Rocky Linux, AlmaLinux, and CentOS  
sudo apt install htop -y   # For Debian-based distributions like Ubuntu  

Once installed, launch it with:

htop

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.

3️⃣ Footer Section – Keyboard Shortcuts

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

sudo dnf install stress -y

Step 2: Simulate CPU Load

Run the following command to generate 4 CPU-intensive tasks for 60 seconds:

stress --cpu 4 --timeout 60s

Now, open htop on Linux in another terminal:

htop

You’ll notice CPU usage spiking with red bars indicating high utilization.

Step 3: Simulate High Memory Usage

stress --vm 2 --vm-bytes 500M --timeout 60s

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:

pkill stress

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:

htop -u developer  # Replace 'developer' with the actual username

In my case, since I don’t have a developer user, I will use:

htop -u sysadmin

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
    Press F10 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:

htop -u username

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.


See also:

List of monitoring tools 

Linux Blogs

AWS Cloud Blogs

Database Blogs

DevOps Blogs

Interview Questions & Answers

Docker Blogs

Google Cloud Blogs







Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.