Htop is an enhanced version of top command. It displays all processes running on the system by PID plus uptime, load average, memory utilization, and other important statistics. It shows the information in a well-organized manner, which allows the users to find the system matrics easily. In this tutorial, we will look at how we can retrieve the system information with the use of htop command in CentOS8. It works on all Linux distribution and comes up installed by default in most cases.
To verify if the package is installed or not, open up the terminal and use the following command.
# rpm –q htop
As shown in the screenshot above, the package not installed. To install the htop package in CentOS 8, open up the terminal and use the following command.
# dnf install –y htop
After the installation is complete, it’s a time to retrieve the system metrics, for this use the following command.
It will retrieve all the system metrics, as shown below.
htop command Sections
There are different sections in htop command those sections, are as follows.
- Header Section
- Footer Section.
The header section shows information about system metrics, which includes CPU, memory utilization, load average, Tasks, Swap utilization, and uptime.
The body section includes metrics like Process ID’s, user who owns that process, memory utilization, CPU and the time, etc.
The footer section includes the htop menu section.
htop command usage
Now, we can perform several actions with the use of htop command, these actions are as follows, and we will discuss it one by one.
- Sorting output.
- List processes in a tree-like format.
- Filtering processes.
- Searching a Process.
- Killing a Process.
Htop command provides multiple options to sort the output. To sort out the metrics navigate to the column header option according to which you want to sort out and click on that option. In the screenshot attached below, I sorted out according to memory utilization. By default, it uses CPU% for sorting.
List Processes in a tree-like format:
To display the process in a hierarchical order, creating a parent-child (inherit) relation. To display the metrics according to the relationship, press the F5 function key. The sample output is attached below.
We can also filter the processes with the help of htop command, for this press F4 function key. It will prompt you to enter the path to filter the metrics and press enter at the footer section. In the output shown below, I have displayed the process by providing the path /usr/libexec.
Searching a process:
We can also search the process with the help of htop command, for this use the F3 function key and enter the process name you want to search. It will highlight that specific process, i searched the libexec process gsd-color. The image attached below used for the reference.
Killing a process:
To kill any process with the htop command, use the F9 function key or the letter K. I have selected the signal and press enter, it will kill the process.
To get further assistance, use the F1 function key. A list of options will appear in front of you, as shown below.
In this tutorial, we learned the use of htop command in CentOS 8. We saw how to kill the process, sorting the processes, searching the specific process, filtering the process, and display the process according to a parent-child relationship. I hope this tutorial will help you with a better understanding of htop command.