Linux htop command
What is htop
htop is an interactive process viewer for Linux systems. It offers richer features and a more user-friendly interface than the traditional top command.
Main features of htop
- Color display: Different colors distinguish different types of processes and system states
- Visual layout: Intuitively display the usage of CPU, memory, and swap space
- Mouse support: You can operate directly by clicking with the mouse
- Process tree view: You can view the hierarchical relationships between processes
- Custom sorting: You can sort processes by various metrics
- Process operations: You can directly terminate processes, adjust priority, and more
Install htop
On Debian/Ubuntu-based systems
sudo apt update
sudo apt install htop
On RHEL/CentOS-based systems
sudo yum install epel-release # 先安装 EPEL 仓库
sudo yum install htop
On Arch Linux-based systems
sudo pacman -S htop
htop basic interface overview
To start htop, simply enter in the terminal:
htop
The interface is mainly divided into the following sections:
-
Top area: System overview information
-
Middle area: Process list
-
Bottom area: Function key hints
htop common shortcut keys
| Keyboard shortcut | Description |
|---|---|
| F1 or h | Show help |
| F2 or S | Enter the settings menu |
| F3 or / | Search processes |
| F4 or \ | Filter processes |
| F5 or t | Display the process tree |
| F6 or < | Select the sort field |
| F7 or [ | Lower the process priority |
| F8 or ] | Raise the process priority |
| F9 or k | Terminate a process |
| F10 or q | Exit htop |
| Space Key | Mark/unmark processes |
| u | Display processes of a specific user |
| H | Show/hide user threads |
| K | Show/hide kernel threads |
| P | Sort by CPU usage |
| M | Sort by memory usage |
| T | Sort by running time |
htop advanced features
1. Process tree view
Press F5 or t You can switch to the process tree view to display the parent-child relationships between processes.
2. Process filtering
Press F4 or \ You can enter a filter condition to display only processes that match.
3. Multi-select operations
After marking multiple processes with the space bar, you can perform batch operations (such as termination).
4. Custom display
Press F2 Enter the settings menu to:
- Adjust the displayed columns
- Change the color theme
- Set the refresh interval
- Configure other display options
5. System monitoring
The top area of htop provides rich system monitoring information:
- CPU usage (by core)
- Memory and swap space usage
- System load average
Comparison of htop and top commands
| Feature | htop | top |
|---|---|---|
| Interface | Colored, intuitive | Monochrome, basic |
| Mouse support | Is | No |
| Process tree view | Supported | Not supported |
| Sorting method | Multiple, can be adjusted dynamically | Limited |
| Process operations | Richer | Basic |
| Customization | Highly configurable | Limited |
| Resource usage | Slightly higher | Lower |
Practical Application Examples
Example 1: Find and terminate a process with high CPU usage
- Start htop
- Press
PSort by CPU usage - Find the target process
- Press
F9Select the termination signal (usually 15 SIGTERM) - Press Enter to confirm
Example 2: Monitor the processes of a specific user
- Start htop
- Press
uKey - Select the user name to monitor
- Display only that user's processes
Example 3: Set the refresh interval
- Press
F2Enter the settings - Select "Display options"
- Modify the "Delay" value (seconds)
- Press
F10Save and exit
Frequently Asked Questions
Q1: Which is better, htop or top?
htop provides richer features and a more friendly interface, suitable for interactive use; top is more lightweight, suitable for use in scripts.
Q2: Why do some processes appear green/red?
Green usually indicates a normally running process, while red may indicate high resource usage or a zombie process.
Q3: How do I view the full command line?
Press F2 Enter the settings and adjust the "Show program path" option in "Display options".
Q4: What does the memory information displayed by htop mean?
- VIRT: The total amount of virtual memory used by the process
- RES: The physical memory used by the process
- SHR: The shared memory used by the process
Linux Command Reference