How to Manage Linux Processes With htop


System monitoring allows you to measure the performance of your Linux applications and services. You can measure processes and services using default tools or ones that you install yourself. With these programs, you can optimize performance, spot problems, and identify their source.

The htop command is an interactive system-monitoring tool for Linux and Unix-like systems. It's an alternative to the default command-line tool, top, that comes pre-installed on all Linux distributions.

This article explains how htop is different from the top utility. You'll see how to install htop on various Linux distributions or build it from the source. And you'll find out how to more around htop's interface and perform system monitoring using shortcut keys or your mouse.

htop vs. top

htop has many benefits over the default top program. Here are just a few of them:

htop top

Colorful visualization and better text-based interface Basic user interface Scrolls horizontally and vertically No scrolling support, processes update every 5 second Supports mouse operations Does not support mouse operations Display kernel and user threads Displays process with no context Can control processes directly from the interface Requires you to leave the Top command interface to kill/renice a process Allows you to kill multiple processes at once without requiring their PID Requires PID to kill a process Does not require priority value or process ID to renice Requires priority value/PID to renice a process

Related: How to Display Top Processes Results and Sort by Memory

htop Installation on Various Linux Distributions

If you just want a recent version of htop, you can find a package for all popular Linux distributions. You can quickly install it using your package manager with one of the following commands:

On Debian

sudo apt install htop

On Ubuntu

sudo apt-get install htop

On Manjaro/Arch

pacman -S htop

On CentOS Or RHEL8/7

sudo yum -y install #RHEL8sudo yum install htop
sudo yum -y install #RHEL7sudo yum install htop
yum -y install epel-release #CentOSyum -y updateyum -y install htop

On Fedora

sudo dnf install htop


sudo zypper install htop

Alternative Ways to Install htop

Compile htop From the Source Code

htop is an open-source project, so you can get the code and build it yourself to get the latest version with all new features and updates.

htop uses the ncurses library which you'll need to install, along with its development tools. You can do so for RHEL/CentOS/Fedora based distributions, as follows:

yum groupinstall "Development Tools"yum install ncurses ncurses-devel

To build htop for a Debian/Ubuntu distribution:

sudo apt-get install build-essentialsudo apt-get install libncurses5-dev libncursesw5-dev

Now download the latest version of htop from its GitHub repository and extract it with the tar command:

wget -O htop-2.0.2.tar.gz xvfvz htop-2.0.2.tar.gz

Then move into the htop directory and use configure followed by the make command to install/compile htop:

cd htop-2.0.2./configuremakesudo make install

From Snap

Another way to install the latest version of htop is with the third-party package manager snap-store. This is a cross-distribution application management and development system.

For htop installation in Ubuntu via snap, you need to install/enable snapd:

sudo apt updatesudo apt install snapdsudo snap install htop 

You can find details about htop installation on other Linux Distributions from the official Snap Store website.

Understanding the htop Interface

After installation, run the htop command in a terminal to view the interface shown below:

Htop Interface

The htop interface has three main panels. Let's explore the information displayed in each panel.

The Header

The header splits the top of the interface into left and right sections. These display the CPU/memory usage, swap space, the machine uptime, tasks, and average load.

Htop Header

The top-left section shows one line for each CPU core. For instance, the above screenshot displays two CPU cores, with the percentage representing the load on each.

You can also see the color-coding provided by htop to identify what kind of processes are using the CPU:

  • Red: percentage occupied by system processes
  • Blue: percentage occupied by low priority process
  • Green: percentage occupied by user processes

The memory lines also use color-coding, this time to represent:

  • Yellow: percentage occupied by cache content
  • Green: percentage occupied by the used memory
  • Blue: percentage occupied by buffer content

The Mid-Panel

The center panel shows all the running processes with their associated stats based on CPU utilization. It displays the following information for each process:

  • process ID (PID)
  • the owner (User)
  • virtual memory consumption
  • percentage of processor
  • physical memory

You'll be familiar with this part of the display if you've used the top command.

Htop Mid Panel

The last panel demonstrates just a few of htop's interactive features. It contains all the necessary options to work around the htop graphical interface.

Htop Footer

For instance, press F3, and you will notice a space to enter the program name to find its associated process. You can also use your mouse to click on F3 in the footer. Another way to perform a search is to type '/' since htop supports vi-like editing.

Htop Terminal Program Search

Select F2 to enter the settings menu to set meters, change the display options, colors and add/remove columns from the mid-panel.

Htop Setup

Here's how you can move an element of the htop interface within the header. Start by selecting Swap [Bar] using cursor keys, then press Enter or click on Move in the footer:

Setup Swap Using Move Option

Then, use the cursor keys to position the field and click on Done to complete the move:

Setup Swap by Clicking Done Option

You can also add a new meter to the htop interface. Select any from the Available meters column and click on Add to include it (or Done to cancel).

Htop Add New Meter

The F9 key opens an interface listing all options available in the kill -l command to send the kill signal to the selected process. Use the default SIGTERM signal if you are unsure which to use.

Htop F9 Key

htop Keyboard Shortcuts

Function / Shortcut Description

u Sort processes by username p Toggle with the program path F2 or S Enter Setup F3 or / Search process F5 or t Sorted or tree view F6 +/- Select the parent process to expand/collapse the tree F7 or [ Increase priority only for root F8 or ] Low priority (nice +) F9 or k Kill process H Toggles with user process threads K Toggles with kernel process threads

htop, the Interactive Tool for Linux System Monitoring

The main differences between htop and top are that htop provides a lot more functionality and is easier to use. System monitoring with a keyboard-only, monochromatic interface can be a daunting task. htop provides many features to ease the task of dealing with processes and their resource use.

htop is a great introduction to system monitoring, providing you know the basics of how a Linux system operates. But there are plenty of other tools which allow you to investigate how your system is running.


How to Seamlessly Switch to Linux from Windows

Previous article

10 Fun Linux Command-Line Programs You Should Try When Bored

Next article

You may also like


Leave a reply

Your email address will not be published.

More in LINUX

Login/Sign up