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 again goes to the next match. F3 Esc exits the search.
F4, \Filter processes. Only processes with command lines having a match for the typed string will be shown. F4 Esc exits the filter.
F5, tDisplay processes in a tree view. This works as a toggle command. Pressing F5 again gives the previous view.
F6, <, >Select a new field for sorting. The selected field is highlighted in the header.
F7, ]Decrement the nice value of process(es). This results in increase of process’s priority and can only be done by the superuser.
F8, [Increase the nice value of process(es). This results in a decrease in process’s priority.
F9, kKill process(es) by sending a signal chosen by the user from a menu.
F10, qQuit htop.
I (eye)Invert the current sort order, changing increasing to decreasing and vice versa.
+In the tree view, collapse a subtree. A + is displayed to the left of the parent process.
aSet CPU affinity. Mark which CPUs a process may use.
uShow processes owned by a user.
MSort the process list by memory usage.
PSort the process list by processor usage.
TSort the process list by time (TIME+).
FFollow. Make the selection bar follow the currently selected process as it moves up or down in the sort order. As a movement key is pressed, the process is unfollowed.
KToggle the display of kernel threads.
HToggle the display of user threads.
Ctrl LRefresh the screen.
NumberSelect the process having the entered process id.
sUsing strace, trace process’s system calls.
l (ell)Using lsof, display open files for a process.
LUsing ltrace, show library calls made by a process.

6.0 htop Command line options

The important htop command line options are given in the following table. For each argument, there is a short and a longer name, either of which can be used. If an argument needs a value, it has to be passed regardless of whether the shorter or the longer name has been used.

Important htop command line options
OptionDescription
-d –delay=DELAYDelay between output updates, in tenths of seconds.
-C –no-color
–no-colour
Run htop in monochrome mode.
-p –pid=PID,PID…Display output for these PIDs only.
-s –sort helpPrint a list of column names, for which the htop output can be sorted.
-s –sort COLUMNSort the output based on COLUMN
-u
–user=USERNAME
Display processes for the user with this USERNAME only.
-v –versionDisplay htop version and exit.

See also

Share

Karunesh Johri

Software developer, working with C and Linux.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments