How to Use htop Command in Linux?

The machine consumes the system resources which can be monitored with the built-in top command. The top command concentrates on the processes which consume high system resources while its advanced command htop displays all the running processes. The htop command helps to monitor the real-time processes with a multi-color display and visual representation of the Processors, CPU & memory consumption, and currently running processes.

The htop command shows dynamic and interactive processes to manage the system resources on a single screen. Considering the importance of the htop command, this article will assist you in using the htop command with different examples. The topics this article covers are:

Let’s start the article.

What is the htop Command in Linux?

The htop command helps the users in monitoring the system resources and processes in real time. It is an advanced version of the top command (used for managing processes) with several newer features. This command comes with a delay option, highlight changes, a colorful display, and visual information about the processors & memory usage.

Primarily, the htop command offers the following usages:

  • Processes information
  • CPU & memory usage
  • Running tasks & load on the system

Let’s install the htop package and move on to the uses.

How to Install htop Command in Linux?

Several Linux distributions do not have “htop” installed. To install the htop in Linux, you should utilize one of the following command utilities as per your Linux distribution:

$ sudo apt install htop                     #Install htop in Ubuntu
$ sudo dnf install htop                     #Install htop in Fedora
$ sudo yum install htop                     #Install htop in CentOS

The htop utility is installed successfully.

Let’s look at the syntax of the htop utility.

Syntax of the htop Command:

$ htop [option] [value]
  • htop: This shows htop command is used.
  • options: Replace with available options.
  • value: Replace with PID or different value.

Options Available in htop Command:

To find the options available in the htop command, run the help command in Linux. The following options are utilized with the “htop” command:

$ htop --help

Now, let’s use the htop command.

How Does the htop Command Work in Linux?

To have the basic usage and the components of the htop command, let’s execute the below “htop” command in the terminal to open the system monitor:

$ htop

The below interface will show running processes interactively:

There are several managing options available in the footer. Let’s discuss the monitoring options shown in the above picture.

CPU and Memory Usage

The system manager shows the CPU & memory usage percentage as shown below. The 0 & 1 shows the two cores of the system, and for multiple core systems, there would be n number of lines (0,1…,n). The 1 number CPU shows that CPU is less consumed.

The Mem line shows the memory percentage used by the running processes in the system.

The different colors represent the system’s consumption.

CPU Colors for htop

  • Green: CPU used by user processes.
  • Blue: CPU used by low-priority processes.
  • Red: CPU used by system processes.

Memory Colors for htop

  • Green: Used Memory.
  • Yellow: Cache Memory.
  • Blue: Buffers.
  • Gray: CPU consumed by Input/Output processes.

Running Tasks & Load on System

It shows the summary of all the tasks running on the system:

  • Tasks: All the processes running on the system, that includes system and user processes.
  • Load Average: shows the percentage use of the CPU based on the cores. For example: if the system has 1 core and 0.10 load means 10% CPU is consumed.
  • Uptime: Shows the time difference between system boot time and current time.

Processes Information

Every system process information is shown on the interface, where we can get the process detail:

  • PID: Process ID for every process.
  • USER: Process owner.
  • PRI: Priority of the process.
  • VIRT: Virtual Memory consumed.
  • RES: The RAM part used by the process.
  • S: State of the running process. R- running, S- Sleeping.
  • CPU%: Percentage time used by the process in CPU
  • MEM%: The usage of RAM process in Percentage.
  • TIME+: Start time of the process.
  • Command: The command which initiates the process.

How to Use htop Command in Linux?

The htop command is very powerful in managing the system processes. This section will elaborate on the uses of the htop command.

Example 1: Use htop for No color

The htop command navigates to the system manager, which has a colorful interface. To remove the color from the system manager, utilize the “C” option with the htop as written below:

$ htop -C

Example 2: Use htop to Filter Processes

The “f” option allows you to find the process details for a specified process. We can use PID or other queries to find a specific process. For instance: for the “5124” value, use this command:

$ htop -f 5124

Example 3: Use htop Command for Delay

The htop provides the option to update the detail of processes for some time. To delay the update of processes in htop for 0.5 seconds, use the following command:

$ htop -d 5

Every process in the output will update after every 5 seconds.

Example 4: Use htop Command to Filter with PID

The “p” option is utilized to filter for the specific processes. To filter the process with PID “5124”, run this command:

$ htop -p 5124

Example 5: Use htop Command to Column Sort

We can use the htop command to sort the display data of processes. The “s” options enable you to sort the data; for instance: to sort the data based on the “PID” column, utilize the following command:

$ htop -s PID

To sort based on the “USER” column, execute this command:

$ htop -s USER

Example 6: Use htop Command to Highlight the Changes

If you want to highlight the changes from the previous and new process, the “H” flag of htop command is used:

$ htop -H

Example 7: Use htop Command to Show Tree Structure

The “t” option, gives us the tree-like structure for the commands. For creating the tree-like structure of commands, use this syntax:

$ htop -t

Example 8: Use htop Command to Show Processes for a Specific User

The “u” flag of the htop command is very helpful in finding the processes by a specific user. To check the “itslinuxfoss” user processes, run this command:

$ htop -u itslinuxfoss

That’s the end of this article.

Conclusion

The htop command is used to manage the system processes like CPU & memory consumption, running tasks, and details of each system process. This command is utilized to find the process for a specific user, highlight certain processes, sort processes based on columns, filter the processes, and many more. This guide discussed the possible uses of the htop command with examples.