How to use htop to Monitor Linux System Processes

Htop is a command-line utility that is an improved version of the top command. It displays crucial system metrics such as tasks running, PIDs, uptime, load average, memory utilization and a load of other important statistics.

What makes htop stand out from its predecessor top command is the ability to display system metrics in a more organized manner and in various color schemes. This allows users to intuitively find the system metrics they want with ease compared to the plain and boring top command utility tool.

In this guide, we look at how you can make the most of the htop command utility to retrieve various system metrics. Htop works across all Linux distributions, and in most cases comes pre-installed with newer versions. To fire up htop and display system metrics, simply type the command htop.

# htop

htop-command-output-linux

Sections of htop command

From the output see earlier on, we can clearly see that htop’s display is categorized into 3 sections:

Header Section:

The header section displays system metrics which include CPU, Memory and Swap utilization, running tasks, load average, and uptime.

htop-header-linux

Body:

This section lists all the running processes.

htop-body-linux

Footer Section:

This displays’ htop menu options

htop-footer-linux

Some of the advantages of using htop over top command include:

  • Ability to use the mouse to interact with htop utility.
  • System metrics are color-coded to make it easier to identify at a glance.
  • Htop provides a way of killing a process without invoking its PID.
  • You can scroll up and down using the mouse or Arrow up & arrow down keys to have a view of all the running processes.

Sometimes, you may get a warning when working on a system without htop installed. To install htop run the commands below:

For Debian/ Ubuntu/Mint

# apt install htop

For RHEL / CentOS

# yum install htop

For Fedora 22 and later

# dnf install htop

Using htop command

Let’s now shift gears and see the various options that come with the htop utility tool.

Sorting output

Htop provides multiple options that you can use to sort your output. To view the output options, simply hit the F6 function key on your keyboard. On the left section, scroll and select the criteria that you want to use when sorting the output. By default, this is set to the PERCENT_CPU  option.

sort-linux-process-cpu-htop

To sort using Memory Percent utilization, use the down-arrow key and hit ENTER on the PERCENT_MEM option.

sort-process-memory-based-htop

List processes in a tree-like format 

Linux processes are usually in a hierarchical order, creating a child-parent relationship. To display the relationship, simply press the F5 function key.

tree-like-process-linux-htop

Filtering Processes

Linux processes can also be filtered according to their respective paths. To filter processes, press the F4 function key. You will be prompted to enter the path of the process at the footer section. In the output below, I have displayed the processes in the /usr/sbin path.

Filter-linux-process-htop-command

Searching Processes 

You can also search for a process by simply pressing the F3 key and typing the name of the process in the search prompt that appears at the bottom of the terminal screen.

For instance, in this case, I’m searching for the rsyslogd process in the /usr/sbin path. Once located, the process will be highlighted in yellow.

Searching-Linux-Process-htop-command

Killing a process 

After launching htop, simply scroll to the process you want to terminate or ‘kill’. In this case, I have selected Jenkins with a PID of 1983.

kill-linux-process-htop-command

Next, press the F9 functional key or the letter k and select the signal that you want to send. In this case, I have selected SIGKILL to ensure the process quits.

kill-signal-htop-command

Then finally press ENTER.

How to customize htop output

To make a few tweaks here and there that will determine how your output looks like, hit the F2 key. Several options will be available to change for instance colors, font style of system metrics to mention a few.

Customize-htop-command-output

Getting help

To get assistance on how to find your way with htop and best leverage the various shortcuts therein, simply hit the F1 key. A list of key options and what they do will be displayed as shown.

Getting-help-htop-command

And this brings us to the end of this topic on htop command. Feel free to comment and share it with your friends 🙂



from Linuxtechi https://ift.tt/2LYJzCT

Post a Comment

0 Comments