The htop is a cross-platform interactive process-viewer. It's a more user-friendly and feature-rich command than the traditional top command. htop requires the 'ncurses' library, which allows the program to provide a text-based graphical user interface.
You can find the configuration file in user home directory in $HOME/.config/htop/htoprc. It contains various settings that control the behavior and appearance such as color themes, how to display columns, and sort processes, etc.
Key features are:
- Scroll vertically and horizontally - This allows you to see all processes and all columns.
- Top interface shows an overview of CPU, memory and swap in color.
- Display processes in a hierarchical tree view.
- Can action on multiple processes
- Can easily search and filter processes.
- Can attach strace to a process to view the system calls it is making
Before you can use htop, you need to install it. It's not included in all Linux distributions by default.
On Ubuntu/Debian-based systems, use:
sudo apt-get update
sudo apt-get install htop
On Fedora, use:
sudo dnf install htop
On RHEL, use:
sudo yum install htop
You can find the latest binary and source code on the download page.
Understanding the 'htop' Interface
CPU Usage: In the top left corner, Htop visualizes the number of CPU cores and their load. The load is represented by small progress bars. Furthermore, it shows a load of each CPU core as a percentage value.
Memory usage: Right below the CPU status, we can see the system's physical memory consumption. These progress bars represent the amount of RAM consumed by the processes running on your machine.
Swap usage: displays this swap memory usage information using colored progress bars.
Load average: In the top-right half, Htop displays the average CPU load.
The bulk of the interface lists all currently running processes, with details like process ID (PID), user, priority, virtual memory usage, CPU, and memory percentages, running time, and command line.
Footer: The bottom has a menu with command shortcuts. For example, 'F9' brings up the kill menu, allowing you to send various signals to a process.
Key 'htop' Commands/Shortcuts
F1 or ?: Open the help screen
F6: Sort processes by various attributes (PID, USER, CPU, MEM etc.)
We can sort the processes based on a column. Hit the F6 key on your keyboard and a new column named ‘Sort by’ will appear on the leftmost side.
F3: Search for a process
At the bottom, we will be getting a search input field to enter the phrase or name of the process.
F9: Kill a process
Hit the ‘F9’ or ‘k’ key on your keyboard. Upon that, you will see a new column named ‘Send Signal:’ on the left-most side of the current view.
Since we are going to kill a process instance, SIGKILL should be selected and hit enter. The selected process instance will be killed.
F4: Filter processes (e.g., by user)
Example: Hit on the F4 key and a search bar will appear at the bottom. There you can enter the process path for instance 'lib/systemd' - then It will show only processes filtered by the 'lib/systemd' command.
You can use the 'S' key on the keyboard to trace process system calls for a filtered process instance.
- Arrow keys, PgUP/PgDn, Home/End: Navigate the list.
- Space: Tag a process.
- F2: Access setup/settings.
- F5: Tree view - shows parent/child process relationships.
- F7/F8: Increase or decrease the nice value of a process, affecting its priority.
- F10 or q: Quit 'htop'.
- s: Attaches strace to the highlighted process, allowing users to monitor the system calls it makes in real time.