htop
Overview
The htop command is an interactive process viewer and system monitor. It’s an enhanced version of top with a more user-friendly interface and additional features.
Syntax
htop [options]Common Options
| Option | Description |
|---|---|
-d delay |
Update delay in seconds |
-u user |
Show only user’s processes |
-p pid |
Show only specific PIDs |
-s column |
Sort by column |
-C |
No color mode |
-h |
Show help |
--tree |
Show process tree |
Interactive Keys
| Key | Action |
|---|---|
F1 |
Help |
F2 |
Setup |
F3 |
Search |
F4 |
Filter |
F5 |
Tree view |
F6 |
Sort by |
F7 |
Nice - |
F8 |
Nice + |
F9 |
Kill |
F10 |
Quit |
Space |
Tag process |
U |
Untag all |
t |
Tree mode |
H |
Hide/show threads |
Display Information
| 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 | Command line |
Key Use Cases
- Monitor system performance
- Identify resource-heavy processes
- Kill problematic processes
- Analyze memory usage
- Track CPU utilization
Examples with Explanations
Example 1: Basic Usage
htopLaunches interactive process monitor
Example 2: Show Specific User
htop -u apacheShows only apache user’s processes
Example 3: Tree View
htop --treeDisplays processes in tree format
Process Management
- Kill process: Select and press F9
- Change priority: F7 (decrease) or F8 (increase)
- Search processes: F3
- Filter processes: F4
- Tag multiple processes: Space
System Information Display
Top panel shows: - CPU usage per core - Memory usage (RAM/Swap) - Load averages - Uptime - Task counts
Customization Options
- Setup menu (F2):
- Display options
- Colors
- Columns
- Meters
- Column configuration:
- Add/remove columns
- Reorder columns
- Change column width
Common Usage Patterns
- Find memory hogs:
- Sort by %MEM (F6 → M)
- Look for high RES values
- Find CPU intensive processes:
- Sort by %CPU (F6 → P)
- Monitor over time
- Process tree analysis:
- Enable tree view (F5)
- Expand/collapse with +/-
Performance Analysis
- Real-time updates
- Low system overhead
- Efficient display
- Responsive interface
- Minimal CPU usage
Additional Resources
Best Practices
- Use tree view for process relationships
- Monitor trends over time
- Use filtering for specific analysis
- Customize display for your needs
- Learn keyboard shortcuts
Advanced Features
- Strace integration:
- Select process and press ‘s’
- Lsof integration:
- Select process and press ‘l’
- Process following:
- Follow process children
Installation
Most distributions include htop:
# Ubuntu/Debian
sudo apt install htop
# CentOS/RHEL
sudo yum install htop
# Arch Linux
sudo pacman -S htopConfiguration
Config file location: ~/.config/htop/htoprc - Saves display preferences - Column configurations - Color schemes - Sort preferences
Troubleshooting
- Permission issues for some processes
- High refresh rate impact
- Terminal compatibility
- Color display problems
- Memory usage of htop itself
Comparison with top
Advantages over top: - Color display - Mouse support - Easier navigation - Better process tree - More intuitive interface - Horizontal scrolling
Integration Examples
With scripts:
htop -d 1 -p $(pgrep firefox)Remote monitoring:
ssh server htopAutomated screenshots:
htop -C > process_snapshot.txt