Htop is very interactive, gives you additional information about running processes, and allows for manipulations such as sorting the list of processes using various criteria and search for a process/kill processes. While top command takes few seconds delay to collect data where htop is much faster.
In this tutorial, I will show you how to install and use htop on Redhat 8, CentOS 7, Ubuntu 16.04 and Fedora. We'll also explore the htop keyboard shortcuts and screen column information.
Table of Contents
$ sudo apt-get update $ sudo apt-get install -y htop
$ sudo dnf install htop
CentOS 7 or RedHat 7
$ sudo yum install htop
EPEL repo for RHEL 8
sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm sudo yum update
Compiling from source
To compile htop from source, we need to have ncurses4 or newer and development tools/build essential installed. Here are the steps to installing htop from source.
$ wget -qO- wget http://hisham.hm/htop/releases/2.0.2/htop-2.0.2.tar.gz | tar xvz -C . $ tar zxf htop-2.0.2.tar.gz $ cd htop-2.0.2/ $ ./configure $ make $ make install
If you encountered an error during compiling, then it means you don't have one or more of the dependencies installed. Here's how to install your dependencies.
For Ubuntu and debian distros, run the command:
$ sudo apt-get install build-essential libssl-dev libncurses5
For Fedora 26 and newer, use the command:
$ sudo dnf install @development-tools ncurses
For CentOS 7, RedHat 7 and other rpm-based distros, run the command:
$ sudo yum groupinstall "Development Tools" $ sudo yum install ncurses-devel
To launch htop, simply type the command
htop in your terminal. The header shows the CPU averages and the main body of the application contains more information about each process.
Here is what each column means:
PID: A process’s process ID number.
USER: The owner of the process.
PR: The process’s priority. The lower the number, the higher the priority.
NI: The nice value of the process, this affects its priority.
VIRT: The virtual memory the process is using.
RES: The physical RAM the process is using, usually measured in kilobytes.
SHR: The shared memory the process is using.
S: The current status of the process (sleeping, zombied, running, traced or uninterruptedly sleeping).
%CPU: The percentage of the processor time used by the process. It displays the % of CPU used at the end of the bar. The bar itself will shows low-priority in blue, normal in green, kernel in red.
%MEM: The percentage of physical RAM used by the process.
TIME+: The processor time the process has used.
COMMAND: The name of the command that initiated the process.
The footer displays the htop menu commands.
How to use htop
htop is used primarily with the keyboard, but if you have a ncurses6 or newer installed, you can use the mouse to scroll. Here's how you can navigate htop with your keyboard.
Scrolling through processes
Scroll the process list horizontally and vertically with the up and down arrow keys on your keyboard.
Press the F9 key or k to kill a highlighted process. This will display the "Send signal" menu that lists all the available signals that you can send to the running process. If you perform "kill -15" on the selected process, select "SIGTERM" from the menu, and press enter.
Select the process you to renice and press F7 to reduce the nice value of the process. Press F8 to increase the nice value of the process.
Displaying files opened by a process
Select a process and press l to display all the open files by the selected process.
Displaying Processes from a Single User
Press u, will display "Show processes of" menu and show all the users who have processes running. Select a user from that list and press Enter to show all the processes that belong to that particular user. You can also type "htop -u eyram" from the terminal, which will start htop and display the only process that belongs to the user eyram.
Displaying processes sorted by any htop column
By default, htop displays the processes sorted by CPU usage. Press F6 or >, which will open the "sort by" menu, select any one of the categories, and press Enter.
You can also press the P to sort by CPU%, M to sort by MEM%, or T to sort by TIME%.
Displaying processes in tree view
Tree view is used to identify dependencies of a process. Press F5 or t, to display all the related processes in a tree view. You can selectively collapse or expand a specific process tree by pressing the + or - keys respectively.
Htop Setup Menu
Pressing F2 or s opens up the htop setup with 4 main items.
Meters – Changes the behavior of the meter in the header
Display Options – Customizes some of the htop display options
Colors – Chooses a color theme for the htop
Columns – Chooses what columns need to be displayed for the processes in the htop. You can choose from more than 60 columns.
htop remains in the running until you close it. Press Ctrl + C or F10 to quit.
To check your htop version, use the command
htop -v. The latest version as of writing is 2.0.2
In this article, we installed Linux on various Linux distros and had an overview of how it works. Are there any top alternatives you can tell us about? Let us know your comments below.