You always need a handy and user-friendly tool to check the Linux system summary. Viewing the running task statistics often helps you to fix issues in the system.
In this guide, we learn about Linux htop in detail.
Linux Htop is a command-line utility program to monitor the Linux system status and its currently running processes in real-time. It is a more advanced tool than the old-school top command. The Htop utility offers several features including a user-friendly view that supports mouse operations, and vertical/horizontal scrolling capabilities to view processes and commands. Moreover, the Htop command provides statistics related to memory, CPU, and swap usage. Once it is installed, to use just type htop from the terminal to launch it.
Install htop on Linux
Htop packages are available in most of the Linux package repositories. Hence many package managers can handle the Htop installation for your Linux system without a hassle. In this article, we will be covering the Htop installation with widely used package managers such as apt, dnf, yum, and snap store.
install htop using apt
The Debian-based Linux distributions come with the APT package manager. The Htop packages can be downloaded from APT repositories and easily installed using the APT package manager.
Let’s first update the Linux system and repository list.
sudo apt update && sudo apt upgrade
Now we can install the Htop utility directly from the APT repository as shown in the following.
sudo apt install htop
Upon executing the above command, the Htop should successfully be set up in your Linux machine.
install htop using dnf
DNF is the default package manager of Fedora. The Htop program is available in the Fedora base package repository. Hence, we can easily install Htop with the dnf package manager.
Let’s first update the Fedora system packages and repository list as shown in the following.
sudo dnf upgrade sudo dnf update
Next, we can directly run the below command to install the Htop utility from the default Fedora DNF package repository.
sudo dnf install htop
install htop using yum
CentOS is based on the Red Hat Enterprise Linux OS and the yum comes as the default package manager. The Htop utility is not available in the default CentOS package repository. Hence, we need to fetch it from the Fedora Extra Packages for Enterprise Linux(EPEL) repository.
Let’s first enable the Fedora EPEL repository as shown in the following.
sudo yum install epel-release
Next, it is recommended to update the CentOS system.
sudo yum update sudo yum upgrade
Finally, we can directly use the ‘yum install’ command to download and install the Htop utility.
sudo yum install htop
install htop using snap store
One of the easiest ways to install the Htop command line utility is using a snap package. Usually, the snap packages are stored in the snap store. Since most of the Linux distros support snap packages, you can use the snap store to find the Htop utility.
Let's open the snap store GUI application by entering the following command in the terminal.
As expected, the snap store application has been opened up.
We can search for the Htop snap package and it would appear as shown in the following.
Next, you can select the Htop snap from the list and click on install button to install it.
The application will ask for the system password for authentication purposes and the installation will finish within a few seconds.
The Htop is an interactive process viewer that presents a lot of useful information to its end-users. The view's body region displays all the running process instances with their associated properties. Furthermore, this graphical view updates dynamically with the system changes.
Each table column shows the associated property values for all the running processes at a given time. Let’s list down the information that each column presents.
- Each Linux process instance is associated with a unique system-generated ID. The PID column shows that ID value.
- Usually, a process instance is owned by a Linux user such as root or other custom user. The username or user id of the process owner will be displayed in this column.
- Normally, a process instance is picked from an execution queue. Linux kernel assigns a priority per each process and processes it based on that. The shown values are calculated by adding twenty to the process’s nice value.
- This column displays the nice value of a process instance that ranges from 19 to -20. Higher the value means priority is lower.
- The VIRT column shows the virtual memory that a process is using.
- Each process takes some amount of your system's RAM or physical memory. This is the resident memory size of a process instance that comprises data, text, and stack. This is measured by kilobytes.
- The VIRT column shows the virtual memory that a process is using. The SHR value denotes how much shared memory a process is using.
- The S column displays the current state of the running process instance. Several state values can be seen such as S for sleeping, R for running, Z for zombie or waiting for the parent process to query its exit status, etc.
- Each process instance uses a portion of CPU time. This percentage value is displayed by this column.
- This column shows the percentage value of the amount of physical memory a process is using.
- The processor time a process has consumed. It is measured by clock ticks.
- A process needs to be started by a command. This column shows the command used to initiate the process instance.
How to use Htop
The Htop’s top half view is dedicated to displaying the information related to current system statuses such as CPU consumption, memory usage, swap area usage, Tasks status, load average, etc. To present the information clearly, that section is divided into sub-sections like the top left corner is dedicated to CPU and memory usage details and the top right corner is mainly for average load information. The currently running process instances are shown as a table view in the body section.
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. Additionally, the small progress bars are made up of different colors as shown in the following.
In the above example, the system has only four CPU cores. Hence, it displays four rows per core with small progress bars in front that indicate the load of each CPU. If it is a single core CPU, only one row will appear. In this case, we can see green and red-colored bars. The green bars indicate the load comes from the user processes. The kernel processes are indicated by red bars. You might notice progress bars with different colors in your system. Hence, the following colors have different meanings.
Grey: Wait time for Input/Output operations
Blue: The processes that have very low priority.
Other than these colors, Yellow and Magenta colors may appear which denote IRQ time and soft IRQ time respectively.
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. It is shown as colored progress bars.
In the above example, the available system RAM is 3.67GB and 3.14GB of memory pages have been used.
Linux swapping is acquiring space from or to computer physical storage. Htop displays this swap memory usage information using colored progress bars as shown in the following.
In this example, the system has an 11GB paging area and 666Mb has been consumed by system processes. There might be Blue and Yellow progress bars appearing in your system which indicate the buffer pages and cache pages load average..
In the top-right half, Htop displays the average CPU load. It includes three values as shown in the following.
The first value indicates the one-minute load average. The second value denotes the five minutes average and the last indicates the fifteen minutes load average.
In this example, the one-minute average is 1.40, which means considerably low CPU usage, because this CPU consists of 4 cores. A four-core CPU can have a maximum of 4.0 load average which means the 100% usage of the processor.
1. View the Htop help page
The help page is very useful if you are a newbie to the htop utility program because it lists down all the shortcut keys used to perform different operations within the tool. The F1 key can be used to view the htop help page as shown in the following.
This can be seen as a man page for htop utility.
2. Sorting processes
As mentioned, htop displays the currently running process instances in a table like view. 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 left most side.
Next, select the column name that you need to sort the processes and hit Enter. In this case, we have sorted by user name.
3. Searching process instance
The htop utility program lists a lot of process instances. It is cumbersome to scroll down to find a specific process among hundreds. Hence, the htop provides a searching feature. Hit F3 on your keyboard. At the bottom, we will be getting a search input field to enter the phrase or name of the process.
In this case, we are entering the ‘smartcard’ phrase as the search term and hitting enter. It would highlight the matched process instance in yellow color. Hence, Htop will show only the processes running that match the search text specified.
4. Terminating process instance
In some scenarios, you might need to terminate or stop a specific process instance. Let’s select the process instance you need to kill. Then, 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.
5. Filter processes
The listed process instances can be filtered based on the command paths. You can hit on the F4 key and a search bar will appear at the bottom. There you can enter the process path as shown in the following. It will show only processes whose command paths match with the specified search text. In this example, processes are filtered by the 'lib/systemd' command path.
In addition, you can use the 'S' key on the keyboard to trace process system calls for a filtered process instance.
In summary, the Htop is a command-line utility program that can be identified as a more advanced version of the Linux top command. It provides information on the current system status and its running processes. Now that you know, most of the existing Linux package managers can be used to install the Htop utility. Also, it allows users to scroll horizontally and vertically, do mouse operations and execute commands on processes. As discussed, the body view of the Htop program contains all the running process instances and their details such as process priority, owner, id, etc. It displays most of the high-level information on CPU usage, swap usage, and Load average of your machine. Furthermore, the article stated that the Htop facilitates end-users to execute commands against processes and format the output as preferred.