Monitoring system resources is a daily task for any Linux administrator. While the traditional top command is installed on almost every Unix-like system by default, its interface is dated, monochrome, and sometimes difficult to read. The modern, vastly superior alternative is htop. It provides a colorful, interactive, and highly readable real-time dashboard of your system’s CPU, memory, and running processes.
How to Install htop
Unlike top, htop is not always pre-installed on every Linux distribution. Fortunately, it is available in almost every default package repository.
To install it on Debian or Ubuntu-based systems, use:
sudo apt update && sudo apt install htop
To install it on RHEL, CentOS, or Fedora-based systems, use:
sudo dnf install htop
Understanding the htop Interface
Once installed, simply type htop in your terminal and press Enter. The interface is divided into two main sections.
The Top Dashboard (Resource Meters)
At the very top of the screen, you will see visual bar graphs.
- CPU Bars: You will see a numbered bar for every CPU core on your system (e.g., 1 through 4 for a quad-core processor). The color coding is important: Green represents normal user processes, Red represents kernel/system processes, and Blue represents low-priority (nice) processes.
- Mem (Memory): This bar shows your RAM usage. Green indicates used memory, Blue indicates buffers, and Yellow indicates cache.
- Swp (Swap): This shows how much of your disk-based swap space is currently being used to offset full RAM.
- Load Average: These three numbers represent the system load over the last 1 minute, 5 minutes, and 15 minutes.
The Bottom Dashboard (Process List)
Below the meters is a scrolling list of every process currently running on the server, showing the Process ID (PID), the user who owns it, CPU/Memory consumption percentages, and the exact command used to launch it.
How to Interact with htop
The biggest advantage of htop over top is interactivity. You can use your mouse to click on columns, or use your keyboard for rapid navigation.
- Scrolling: Use the Up and Down arrow keys to scroll through the process list, and the Left and Right arrow keys to view the full command path if it extends off the screen.
- Sorting: Press F6 to open the sort menu. You can quickly sort the list by
PERCENT_CPUto find what is slowing down your server, orPERCENT_MEMto find memory leaks. - Searching: Press F3 to open a search prompt. Type the name of a process (like
nginxormysql) andhtopwill instantly highlight it in the list. - Filtering: Press F4 to filter the list, hiding everything except processes that match your typed keyword.
How to Kill a Process in htop
When you identify a rogue process consuming 100% of your CPU, you can terminate it directly from within htop without needing to open a second terminal window or memorize its PID.
- Use your arrow keys to highlight the problematic process in the list.
- Press F9.
- A menu will appear on the left side of the screen listing various “kill signals.”
- By default,
SIGTERM(Signal 15) is selected, which asks the program to shut down gracefully. Press Enter to send the signal. - If the program is completely frozen and ignores the graceful shutdown, press F9 again, use the down arrow to select
SIGKILL(Signal 9) to forcefully terminate it immediately, and press Enter.
To exit htop and return to your standard terminal prompt, simply press F10 or the q key.