htop is an interactive process viewer and system monitor for Unix systems. It's similar to the classic top command but provides a more user-friendly interface with color-coded information, mouse support, and better visualization of system resources. htop shows a frequently updated list of processes running on your system, sorted by CPU usage by default.
Key Features:
Visual representation of CPU, memory, and swap usage
Color-coded process information
Mouse support for selecting processes
Tree view showing process hierarchies
Easy process management (kill, renice, etc.)
Customizable display and sorting options
Note: htop may need to be installed separately on some systems. Use apt install htop (Debian/Ubuntu), yum install htop (RHEL/CentOS), or dnf install htop (Fedora).
Interactive Keyboard Commands
Key
Action
F1 or h
Show help screen
F2 or S
Setup/configuration menu
F3 or /
Search for processes
F4 or \
Filter processes
F5 or t
Toggle tree view
F6
Select sort column
F9 or k
Kill selected process
F10 or q
Quit htop
Space
Tag/untag process
U
Untag all processes
Command-Line Examples
Example 1: Basic htop Launch
htop
Launches htop with default settings. This displays an interactive interface showing:
CPU usage bars for each core (colored by usage type)
Memory and swap usage bars
List of processes with PID, user, priority, nice value, CPU%, MEM%, and command
System load averages and uptime
Use arrow keys to navigate, F10 or q to quit.
Tip: The color coding in htop helps identify different types of CPU usage: green for normal user processes, red for kernel processes, blue for low priority processes, and cyan for virtualization.
Example 2: Show Processes for Specific User
htop -u craig
Displays only processes owned by user "craig". This is extremely useful for:
Monitoring your own processes without system clutter
Checking resource usage by a specific user
Troubleshooting user-specific performance issues
Managing processes in multi-user environments
You can specify multiple users by repeating the -u option: htop -u craig -u apache
Example 3: Sort by Memory Usage
htop --sort-key PERCENT_MEM
Starts htop with processes sorted by memory usage percentage. This is invaluable when:
Investigating memory leaks
Identifying memory-hungry applications
Troubleshooting out-of-memory situations
Planning system resource allocation
Other useful sort keys include: PERCENT_CPU, PID, USER, PRIORITY, TIME, COMM (command name)
Note: You can also change sorting interactively by pressing F6 and selecting the desired column.
Example 4: Display Tree View
htop -t
Starts htop with process tree view enabled. This shows parent-child relationships between processes:
Visualize process hierarchies and dependencies
Understand which processes spawn others
Identify orphaned processes
See systemd service hierarchies
In tree view, child processes are indented under their parents with connecting lines. Press F5 or t to toggle tree view on/off interactively.
Example 5: Show Full Command Lines
htop -p 1234,5678,9012
Display only specific processes by PID. This example monitors PIDs 1234, 5678, and 9012. Useful for:
Focused monitoring of critical processes
Tracking specific application instances
Observing resource usage of known problematic processes
Comparing multiple related processes
You can find PIDs using ps, pgrep, or pidof commands first.
Tip: Combine with watch: watch -n 2 "htop -p $(pgrep apache2 | paste -sd,)" to continuously monitor all Apache processes.
Example 6: Delay Between Updates
htop -d 50
Sets the update delay to 5 seconds (50 tenths of a second). The default is 1.5 seconds (15 tenths).
Reduce CPU usage of htop itself on busy systems
Get more stable readings on rapidly changing systems
Decrease screen flicker on slow terminals
Extend battery life on laptops
Use smaller values (like -d 5 for 0.5 seconds) for more responsive monitoring of fast-changing processes.
Example 7: No Color Output
htop -C
Starts htop in monochrome mode without colors. This is useful when:
Working on terminals with poor color support
Capturing screenshots or documentation
Using screen readers or accessibility tools
Redirecting output or logging sessions
Personal preference for monochrome displays
The information is still organized clearly using different text attributes and formatting.
Example 8: Filter by Process Name
htop -F apache2
Starts htop with a filter showing only processes matching "apache2". This immediately filters the view:
Focus on specific applications or services
Monitor all instances of a particular program
Troubleshoot service-specific issues
Quick access to related processes
You can also set filters interactively by pressing F4 or \ and typing the filter string.
Note: The filter is case-sensitive and uses substring matching. To clear the filter, press F4 and delete the filter text.
Example 9: Start with Specific Configuration
htop --no-mouse
Disables mouse support in htop. Other useful startup options include:
--no-mouse - Disable mouse support (useful for copy/paste operations)
--readonly - Disable all system modifications (kill, renice, etc.)
--tree - Start in tree view mode
--highlight-changes - Highlight new and ended processes
These options help customize htop for specific use cases or security requirements.
Tip: Use --readonly when demonstrating htop to others or in production environments where accidental process killing must be prevented.
Example 10: Combined Options for System Monitoring
htop -d 30 -t -u root --sort-key PERCENT_CPU
Combines multiple options for comprehensive system monitoring:
-d 30 - Update every 3 seconds
-t - Show process tree
-u root - Show only root processes
--sort-key PERCENT_CPU - Sort by CPU usage
This configuration is perfect for monitoring system services and identifying CPU-intensive root processes in a hierarchical view.
Real-world scenario: A sysadmin investigating unusual system behavior might use this to identify if system services (running as root) are consuming excessive CPU, while the tree view helps understand which services are spawning resource-heavy child processes.
Common Interactive Operations
Killing a Process
To kill a process in htop:
Navigate to the process using arrow keys
Press F9 or k
Select the signal (15 - SIGTERM is default, 9 - SIGKILL for force kill)
Press Enter to confirm
Always try SIGTERM (15) first, which allows the process to clean up. Use SIGKILL (9) only if the process doesn't respond.
Changing Process Priority
To renice (change priority of) a process:
Select the process with arrow keys
Press F7 to decrease priority (higher nice value)
Press F8 to increase priority (lower nice value)
Nice values range from -20 (highest priority) to +19 (lowest priority). Normal users can only decrease priority (increase nice value) of their own processes.
Color Coding Reference
CPU Bar Colors
Green: Normal user processes
Red: Kernel processes
Blue: Low priority processes (nice > 0)
Magenta: Virtualization processes
Cyan: I/O wait time
Yellow: IRQ time
Orange: Soft IRQ time
Gray: Steal time (in virtualized environments)
Advanced Tips and Best Practices
Configuration File: htop saves its configuration in ~/.config/htop/htoprc. You can back up this file to preserve your customized settings across systems.
Search Feature: Press F3 to search for processes. This is much faster than scrolling through hundreds of processes manually.
Multiple Selection: Use Space to tag multiple processes, then perform operations on all tagged processes at once (like killing them with F9).
Warning: Be extremely careful when killing processes, especially system processes or processes running as root. Killing critical system processes can crash your system or corrupt data.
Memory Display: Press Shift+M to toggle between different memory views (total, used, available, etc.). This helps understand memory usage more clearly.
Comparison: htop vs. top
Feature
htop
top
Interface
Color-coded, visual bars
Plain text, monochrome
Mouse Support
Yes
No
Process Tree
Native support (F5)
Requires special invocation
Horizontal Scrolling
Yes (see full command lines)
Limited
Setup Menu
Yes (F2)
No
Installation
Must be installed separately
Included in most systems
Troubleshooting Common Issues
Issue: htop command not found
Solution: Install htop using your package manager:
# Debian/Ubuntu
sudo apt install htop
# RHEL/CentOS
sudo yum install htop
# Fedora
sudo dnf install htop
# Arch Linux
sudo pacman -S htop
Issue: Cannot kill processes
Solution: You need appropriate permissions to kill processes. You can only kill:
Your own processes (if running as regular user)
Any process (if running as root)
To manage system processes, run htop with sudo: sudo htop
Issue: Display looks corrupted
Solution: This can happen on certain terminals. Try:
Resizing your terminal window
Running reset to reset terminal state
Using htop -C for monochrome mode
Checking your TERM environment variable is set correctly
Related Commands
top - Traditional process viewer (always available)
ps - Report process status snapshot
pgrep - Search for processes by name
kill - Send signals to processes
killall - Kill processes by name
pkill - Kill processes based on name and other attributes