htop command in Linux

  • Post author:
  • Post last modified:August 24, 2023
  • Reading time:10 mins read

1.0 INTRODUCTION

htop is a ncurses based program for viewing processes in a system running Linux. htop is quite similar to the top command. However, since htop is a newer program compared to top, it offers many improvements. htop supports mouse operation, uses color in its output and gives visual indications about processor, memory and swap usage. htop also prints full command lines for processes and allows one to scroll both vertically and horizontally for processes and command lines respectively. htop is authored by Hisham Muhammad.

2.0 INSTALLATION

On Debian based Linux systems, htop can be installed with the command,

$ sudo apt-get install htop

3.0 RUNNING htop

htop can be run from the command line,

$ htop

which, gives an output like this,

htop

Fig. 1 htop output

Broadly, there are two parts in the output. There is a header giving summary information at the top and there is detail data below, one row per process. The header has two columns, the left and the right columns. The header has graphic meters and text counters.

4.0 CONFIGURING htop OUTPUT

4.1 DISPLAY OPTIONS

We can customize the output produced by the htop command. For the output displayed in Figure 1 above, the following display options were selected, (F2 -> Display Options)

htop display options

Fig. 2 htop display options

In the above display option settings, we have chosen not to hide the kernel and the userland threads. We display threads in a different color to separate them from processes, highlight large numbers in memory counters, leave a margin around the header and count CPU numbers from 0 instead of 1.

4.2 CONFIGURING METERS

Similarly, we can configure the meters, (F2 -> meters)

htop meters settings

Fig. 3 htop meters' settings

The last column gives all the available meters. We have the individual CPU usage in the header left column. If we wish to put the average CPU usage in the header right column, we can select CPU average in the fourth column, click Add R (F6) at the bottom menu and have the Average CPU usage (Avg) displayed in the header right column. Similarly, we can have the Clock (Time) displayed, also, in the header right column.

4.3 COLOR CODES

The Help screen gives the color codes for CPU and memory meters. If you are running htop from a GNOME terminal, pressing F1 opens the GNOME Terminal Manual. So, to get to the htop Help screen, one has to click on the F1 Help tab at the bottom left. The Help screen gives the color codes,

htop Help screen

Fig. 4 htop Help screen

4.4 CONFIGURING COLUMNS

We can configure the columns displayed for processes and threads in the task area.

htop column settings

Fig. 4 htop column settings

Click F2 -> Setup -> Columns. All the currently displayed columns are displayed under Active Columns. All the available columns are displayed under Available Columns. To add a column, click on the appropriate column name in Available Columns. Click F5 -> Add. With this, the chosen column should show under Active Columns. You can adjust its place in the htop output by clicking on it in Active Columns and moving it up or down with F7 or F8 respectively. You can remove a column from Active Columns with F9. With F10, you can save the settings and return to the htop summary and process list output.

The manual (man htop) explains all the column values.

If, after extensive customization you wish to return to the initial factory settings, remove the configuration file ~/.config/htop/htoprc.

$ rm -f ~/.config/htop/htoprc

5.0 htop commands

The process list is displayed in the task area below the header. Using the arrow keys, Page Up, Page Down, Home and End keys, we can scroll through the process list. The process under the cursor is highlighted and is the selected process. For working on multiple processes with a single command, we can tag multiple processes. The Space command is used to tag or untag a process. If we press the space bar, the process under the cursor is tagged, if it was untagged earlier, and vice versa. The command, U, untags all previously tagged processes.

The important htop commands are,

Important htop commands
CommandDescription
Arrow keys, Page Up, Page Down, Home, EndScroll the process list
SpaceTag or untag the process under the cursor
F1, h, ?Help
F2, SSetup
F3, /Search the command lines of all the displayed processes for the keyed in string. In the search mode, pressing F3 a