The htop Command — Interactive Process Monitoring in Linux¶
htopis an advanced, interactive process monitoring tool for Linux. It provides all the capabilities of thetopcommand with a more user-friendly interface, color-coded resource usage, mouse support, process searching, tree views, and interactive process management. It is one of the most popular tools used by Linux administrators, DevOps engineers, SREs, and Cloud Architects for monitoring production systems.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand the
htopcommand - Install
htop - Monitor system resources
- Search running processes
- Display process trees
- Manage processes interactively
- Filter process lists
- Troubleshoot production systems
Prerequisites¶
Complete:
- Module 1 – Linux Fundamentals
- Module 2 – Linux Command Line Essentials
- Module 3 – Text Processing
- Module 4 – File Management and Permissions
- Module 5 – Users and Groups
- Module 6 Lessons 1–4
Why Learn htop?¶
Imagine your production server has:
- Hundreds of processes
- High CPU utilization
- Memory pressure
- Multiple users
Using:
works well.
However:
- Navigation is keyboard-driven
- Searching is limited
- Process hierarchy isn't always obvious
htop provides a much more intuitive interface.
What is htop?¶
htop is an interactive system monitor that displays:
- Running processes
- CPU usage
- Memory usage
- Swap usage
- Process tree
- Process owner
- CPU utilization per core
Unlike top, htop supports:
- Mouse interaction
- Color display
- Scrolling
- Searching
- Filtering
Installing htop¶
Ubuntu/Debian:
RHEL/Rocky/AlmaLinux:
Older CentOS:
Arch Linux:
Starting htop¶
Run:
Example:
Exit:
Interface Overview¶
The screen contains:
Unlike top, resource usage is displayed using colored progress bars.
CPU Monitoring¶
Displays:
- CPU usage
- Individual CPU cores
- Percentage utilization
Example:
Useful on multi-core servers.
Memory Monitoring¶
Displays:
- Total memory
- Used memory
- Cached memory
- Buffers
- Available memory
Memory usage is color-coded for easier interpretation.
Process List¶
Typical columns:
| Column | Description |
|---|---|
| PID | Process ID |
| USER | Process owner |
| PRI | Priority |
| NI | Nice value |
| VIRT | Virtual memory |
| RES | Resident memory |
| SHR | Shared memory |
| S | Process state |
| CPU% | CPU usage |
| MEM% | Memory usage |
| TIME+ | CPU time |
| COMMAND | Executable |
Search for a Process¶
Press:
Search:
or
Matching processes are highlighted instantly.
Filter Processes¶
Press:
Enter:
Only matching processes remain visible.
Display Process Tree¶
Press:
Example:
Tree view helps identify parent-child relationships.
Kill a Process¶
Select a process.
Press:
Choose a signal.
Example:
Confirm.
Renice a Process¶
Select a process.
Press:
Adjust:
Sort Processes¶
Click a column header with the mouse, or use keyboard shortcuts depending on your version of htop.
Common sorts include:
- CPU%
- MEM%
- PID
- USER
- TIME
Function Keys¶
| Key | Purpose |
|---|---|
| F1 | Help |
| F2 | Setup |
| F3 | Search |
| F4 | Filter |
| F5 | Tree View |
| F6 | Sort |
| F7 | Increase priority (lower nice value, requires appropriate privileges) |
| F8 | Decrease priority (higher nice value) |
| F9 | Kill process |
| F10 | Quit |
Common Commands¶
Start htop.
Display version.
Run as root.
Real Production Examples¶
Monitor Kubernetes.
Search Java.
Filter Docker.
View process tree.
Kill a stuck process.
htop vs top¶
| Feature | top | htop |
|---|---|---|
| Real-time monitoring | ✅ | ✅ |
| Color interface | ❌ | ✅ |
| Mouse support | ❌ | ✅ |
| Process search | Limited | ✅ |
| Process filtering | Limited | ✅ |
| Tree view | Limited | ✅ |
| Easy navigation | ❌ | ✅ |
Production Perspective¶
htop is commonly used for:
- Linux servers
- Kubernetes nodes
- Docker hosts
- Database servers
- CI/CD servers
- Performance troubleshooting
- Incident response
Many administrators prefer htop because it provides more information with less effort.
Hands-on Lab¶
Task 1¶
Install htop.
Task 2¶
Start htop.
Task 3¶
Observe:
- CPU
- Memory
- Swap
- Running processes
Task 4¶
Search for:
Press:
Task 5¶
Filter:
Press:
Task 6¶
Display tree view.
Task 7¶
Sort processes.
Choose:
Task 8¶
Exit.
Command Deep Dive¶
| Command | Purpose | Production Example |
|---|---|---|
htop | Interactive monitoring | Daily administration |
sudo htop | View all processes | Troubleshooting |
F3 | Search | Locate applications |
F4 | Filter | Analyze specific processes |
F5 | Tree view | Process hierarchy |
F9 | Kill process | Process management |
Production Troubleshooting Scenario¶
Scenario
A Kubernetes worker node is responding slowly.
Investigation:
Findings:
- One container runtime process is consuming excessive CPU.
- Memory utilization is normal.
- Process tree shows multiple child processes created by the container runtime.
Next steps:
- Identify the affected workload.
- Review container and application logs.
- Optimize or restart the workload if appropriate.
htop provides a quick visual overview that helps identify performance bottlenecks.
Best Practices¶
- Use
htopfor interactive monitoring and troubleshooting. - Sort processes by CPU or memory usage.
- Use tree view to understand process relationships.
- Search and filter processes to focus on specific applications.
- Confirm process ownership before terminating processes.
Common Mistakes¶
❌ Killing system processes without understanding their purpose.
✅ Avoid this mistake: killing system processes without understanding their purpose.
❌ Assuming high memory usage always indicates a problem.
✅ Linux often uses free memory for caching.
❌ Ignoring parent-child relationships during troubleshooting.
✅ Tree view often reveals the source of unexpected processes.
Interview Questions¶
Beginner¶
- What is
htop? - How does
htopdiffer fromtop? - Which key exits
htop? - Which key searches for a process?
Intermediate¶
- How do you display the process tree?
- How do you filter processes?
- How do you terminate a process from
htop? - Why do many administrators prefer
htopovertop?
Architect Level¶
- When would you use
htopinstead oftop? - How would you investigate high CPU utilization on a production server using
htop? - How does tree view help troubleshoot complex applications?
Summary¶
In this lesson, you learned:
- Installing
htop - Interactive process monitoring
- CPU and memory analysis
- Process searching
- Process filtering
- Tree view
- Interactive process management
- Production troubleshooting
htop is one of the most user-friendly process monitoring tools available for Linux. It combines real-time system monitoring with powerful interactive features, making it an essential utility for administrators and DevOps professionals.
Key Takeaways¶
htopis an enhanced alternative totop.- It provides color-coded, real-time monitoring.
- Use
F3to search andF4to filter processes. - Use
F5to display the process tree. - Use
F9to terminate processes interactively. htopis ideal for troubleshooting production systems.
What's Next?¶
nice and renice — Managing Process Priorities in Linux
You'll explore:
- Process priorities
- Nice values
- Changing process priority
- CPU scheduling
- Performance optimization
- Production workload management
Understanding process priorities will help you control how Linux allocates CPU time among competing processes.