In this short blog I will introduce you to a useful tool called Htop, a process viewer for Linux, which is also available for Mac. In the words of Htop’s author Hisham Muhammad, it aims to be a better alternative to the top program. Among other features it provides full horizontal and vertical scrolling, searching and filtering.
Getting Started with Htop
Install with Apt…
Htop may not be installed on your system by default so you can install it with apt:
$ sudo apt-get install htop
Or, build from source
Alternatively, you can download and build the 1.0.3 version from the htop Github repo. My Ubuntu 14.4 system still uses htop 1.0.2-3 and several bugs have been fixed in 1.0.3 so let’s use the latest version. Note that you might have to install automake, libtool as well as libncurses5-dev, since htop is an ncurses application.
$ wget https://github.com/hishamhm/htop/archive/1.0.3.zip $ unzip 1.0.3.zip $ cd htop-1.0.3 $ sudo apt-get install automake libtool libncurses5-dev $ ./autogen $ ./configure && make $ sudo make install
Here is a screenshot of htop:
Tour of Htop’s features
One great feature is that you can scroll horizontally to the right to view the entire command line of every process. Also, you can use the mouse to select processes or menu items.
Below are a few useful ways to filter processes:
- Filter by user: Press ‘u’, select a user name and hit enter
- Filter by keyword: Press F3, add a term and hit enter
- Sorting: Press F6 ‘Sort By’ and then you can for example select on Percent memory or Percent CPU
Here are some process control features:
- Send signal: Press ‘k’, select a signal number and hit enter
- Strace: Navigate to a process and press ‘s’
Htop can be customized so it displays the information you want. Hit F2 for ‘Setup’ and you can configure display options as well as the columnns it should show. Here is a screenshot of the things I customized:
Under the hood
Htop uses the Linux /proc filesystem to gather information about all processes running on a Linux host. The /proc filesystem exposes a view of information that lives in the kernel so application programs can consume it or in some cases alter it via sysctl.
Since version 1.0.2 htop is XDG compatible. This means that htop uses environment variables such as XDG_DATA_HOME enviromment variables for user configuration. The htop config file is stored under ~/.config/htop.
Even though htop was designed for Linux, the team is working on a port for the Mac, since the current version is 5 years old. A fundraiser is going on to help development.
As you can see htop is an easy to use process viewer. If you have any questions let me know in the comment section. Alternatively if you know more Linux tools like htop that are useful for day to day work let me know. Cheers!