top is the most popular tool used on UNIX/Linux for monitoring. Today we are going to see another one called its alternative tool htop, which is just reached to version 2.0 and comes with some cool new features.
Htop is an interactive real time process monitoring application for Linux/Unix like systems and also a handy alternative to top command, which is default process monitoring tool that comes with pre-installed on all Linux operating systems.
Htop has numerous other user-friendly features, which are not available under top command and they are:
- In htop you can scroll vertically to view the full process list, and scroll horizontally to view the full command lines.
- It starts very quickly as compared top, because it doesn’t wait to fetch data during startup.
- In htop you can kill more than one processes at once without inserting their PIDs.
- In htop you no longer needed to enter process number or priority value to re-nice a process.
- Press “e” to print the set of environment variables for a process.
- Use mouse to select list items.
More detail you can find in http://hisham.hm/htop/
Install Htop Using Binary Packages in Linux
To install Htop on RHEL 7/6/5 and CentOS 7/6/5, your system must have RepoForge (RPMForge) repository installed and enabled, to do so run the following commands on your respective distributions to install and enable it for your system architecture (32bit or 64bit).
On RHEL/CentOS – 32-bit OS
-------------- For RHEL/CentOS 6 -------------- # wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm # rpm -ihv rpmforge-release-0.5.2-2.el6.rf.i686.rpm -------------- For RHEL/CentOS 5 -------------- # wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm # rpm -ihv rpmforge-release-0.5.2-2.el5.rf.i386.rpm
On RHEL/CentOS – 64-bit OS
-------------- For RHEL/CentOS 7 -------------- # wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm # rpm -ihv rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm -------------- For RHEL/CentOS 6 -------------- # wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm # rpm -ihv rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm -------------- For RHEL/CentOS 5 -------------- # wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm # rpm -ihv rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
Once RPMforge repository has been installed, you can hit the following yum command to fetch and install the htop package as shown.
# yum install htop
On Fedora OS
Fedora users can easily install htop using Fedora Extras repository by typing:
# yum install htop # dnf install htop [On Fedora 22+ releases]
On Debian and Ubuntu
In Debian and Ubuntu, you can fetch htop by typing:
# sudo apt-get install htop
Compile and Install Htop from Source Packages
To install Htop 2.0 version, you must have Development Tools and Ncurses installed on your system, to do so run the following series of commands on your respective distributions.
On RHEL/CentOS and Fedora
# yum groupinstall "Development Tools" # yum install ncurses ncurses-devel # wget http://hisham.hm/htop/releases/2.0.0/htop-2.0.0.tar.gz # tar xvfvz htop-2.0.0.tar.gz # cd htop-2.0.0
On Debian and Ubuntu
$ sudo apt-get install build-essential $ sudo apt-get install libncurses5-dev libncursesw5-dev $ wget http://hisham.hm/htop/releases/2.0.0/htop-2.0.0.tar.gz $ tar xvfvz htop-2.0.0.tar.gz $ cd htop-2.0.0
Next, run the configure and make script to install and compile htop.
# ./configure # make # make install
How do I use htop and its Output
htop output consists of three sections
1) header 2) body and 3) footer.
Header displays the following three bars, and few vital system information. You can change any of these from the htop setup menu.
- CPU Usage: Displays the %used in text at the end of the bar. The bar itself will show different colors. Low-priority in blue, normal in green, kernel in red.
- Memory Usage
- Swap Usage
Body displays the list of processes sorted by %CPU usage. Use arrow keys, page up, page down key to scoll the processes.
Footer displays htop menu commands.
Now run the htop monitoring tool by executing following command on the terminal.
# htop
Htop setup
Press F2 or S for setup menu > there are four columns i.e Setup, Left Column, Right Column and Available Meters.
Here, you can configure the meters printed at the top of the window, set various display options, select among color patterns and choose which columns are printed in which order.
Display Processes in Tree View – Press F5 or t
Type tree or t to display processes tree view.
You can refer function keys displayed at footer to use this nifty htop application to monitor Linux running processes. However, we advise to use character keys or shortcut keys instead of function keys as it may have mapped with some other functions during secure connection.
Htop Shortcut and Function Keys
Some of the shortcut and function keys and its functionality to interact with htop.
Shortcut Key | Function Key | Description |
---|---|---|
h | F1 | Invoke htop Help |
S | F2 | Htop Setup Menu |
/ | F3 | Search for a Process |
I | F4 | Invert Sort Order |
t | F5 | Tree View |
> | F6 | Sort by a column |
[ | F7 | Nice – (change priority) |
] | F8 | Nice + (change priority) |
k | F9 | Kill a Process |
q | F10 | Quit htop |
Htop Command Shortcuts and Keys
Display CPU Averages in Header
htop by default displays a separate bar for every CPU (or core) on your system. On a multi core system, the list of individual CPU bar might be a distraction. Instead of multiple bars, you might want to display only one bar for CPU average usage.
Press F2 (or S) for setup menu -> Select “Meters” under setup -> Use right arrow to go to “Available Meters” column -> Use down arrow to select “CPU average” -> Press “F5”, which will add “CPU average” to the list under the “Left columns”.
Now, use left arrow to go to “Left columns” -> select “All CPUs” -> Press F9 to remove it from the “Left columns” -> Use down arrow, select “CPU” -> Press “F7” to move it to the top -> Press to come out of the setup menu.
This will show only the CPU average in the bar as shown below, instead of showing all the individual cores.
Display Processes Sorted by any htop Output Column – Press F6 or >
By default htop command displays the processes sorted by CPU usage. Press F6 (or >), which will display the column names, select any one of the column, and press Enter.
Note: Instead sorting columns by going to sort menu, you can also press the sortcut key “P” to sort by CPU%, “M” to sort by MEM%, or “T” to sort by TIME%.
Kill a Process Without Exiting From htop – Press F9 or k
To kill a process, Select the process that needs to be killed from the list, and press F9 (or k), which will display the “Send signal” menu that lists all the available signals that you can send to the command.
If you want to do “kill -9” on the selected process, select the “SIGKILL” from this menu, and press enter.
Renice a Unix Process Without Exiting From hTop – Press F7 or F8
Select the process that needs to be reniced from the list, and press F7 which will reduce the nice value of the process, press F8 which will increase the nice value of the process by one. If you press F8 three times, it sets the nice value of the process to 3.
Display Only Processes of a Single User – Press u
Press u, which will display “Show processes of” menu and list all the users who has some processes running. Select a user from this list, and press Enter, which will display only the processes that belongs to that particular user.
Note: You can also do “htop -u ramesh” from the command line, which will start htop and display only process that belong to the user ramesh.
8. Change the Output Refresh Interval
To change the refresh interval of the htop output, use the -d command line option. “htop -d x”. Where x is referred in thenths of seconds.
htop -d 10
9. Htop Setup Menu – Press F2 or S
The following are the 4 high-level menu items available in htop setup.
- Meters – Change the behaviour of the meter bar in the header
- Display Options – Customize some of the htop display options
- Colors – Choose a color theme for the htop output
- Columns – This is extermly helpful when you are debugging a problem. Choose what column needs to be displayed for the processes in the htop output. This has more than 60 columns that you can choose from.
Strace a Process from htop – Press s
You can attach the selected process to strace by pressing s. This will display live update of the strace output displaying the system calls invoked by the selected process as shown below.
Display lsof Output inside htop – Press l
Select a process from the htop output and press l, which will display all the open files by the selected process. This uses lsof.
Scroll Process list Hoziontally and Vertically
Unlike top, in htop you can scroll the process list both horizontally and vertically. Select a process and press down arrow key which will scroll the list vertically and show you more processes in the list. You can also press “Page Up” or “Page Down” key to scoll the process list.
Select a process and press right arrow key which will scroll vertically to display the full command line of the process.
Follow a Process in htop Output – Press F
Select a process, and press F, which will follow the process. Since the htop output is sorted based on a column (by default %CPU), a process will keep changing its position in the list.
Following a process in the htop output is helpful when you are monitoring a particular process.
Kill Multiple Processes using Tag – Press Space and F9
You can group multiple processes by tagging them. Select a process, and press “Space bar”, which will tag the selected process. Once a process is tagged, the color of that line will change indicating that it is tagged. Scoll the list and tag multiple processes, and press F9, which will display the kill menu, from where you can kill all the tagged process.
Note: To untag a specific process, highlight that process, and press space bar again. To untag all processes press U.