Htop is a command-line utility on Linux for monitoring system resources and processes in real-time. It is top command’s newer version on steroids, and in Windows terms, htop is your Task Manager’s counterpart.
Htop is a tool for monitoring crucial system metrics like load average, running tasks, PIDs, memory, swap usage, CPU utilization, and other critical statistics. A cool thing about htop is it can show you not just your average CPU usage; instead, it can show your CPU usage per core.
Aside from that, it also shows meaningful text graphs of swap usage and memory right at the top by default. It is much easier to understand compared to the default output from the top command.
Htop will work across all Linux distros, and in most cases, it will come pre-installed in the newer versions. What makes htop better than its predecessor top command is its ability to display metrics in a more organized manner. You can even adjust its color scheme and customize the metrics you want to display.
htop command can be used to:
- Kill certain processes
- Suspend a process, and its child
- Monitor a customized set of statistics
- Filter through processes
- Check system uptime
- Display processes owned by particular users
- Set IO priorities
- Interactively manage operations using a mouse
- Save Terminal output to a file
- See how well a process utilizes CPU cores
This is what the basic syntax for
htop looks like:
$ htop [-dChusv]
htop Command: Different Options
-d --delay=DELAY: This will show the delay between updates, in tenths of a second.
-C --no-color --no-colour: To start htop in monochrome mode, use this option.
-h --help: This will display a help message and then exit.
-u --user=USERNAME: Used to show only the processes of a given user.
-p --pid=PID, PID…: This will show only the given PIDs.
-s --sort-key help: This will print a list of columns.
-s --sort-key COLUMN: This will sort the output based on a column.
-v --version: This will output the version information and then exit.
-t --tree: This will show processes in tree view.
Commands used while in htop:
- Up, Alt-k: This will select or highlight the previous process in the list. Scroll the list up.
- Down, Alt-j: This will select or highlight the succeeding process in the list. Scroll the list down.
- Left, Alt-h: Scroll the list left.
- Right, Alt-l: Scroll the list right.
- PgUp, PgDn: Scroll up or scroll down one window.
- Home: This will scroll to select the first process.
- End: This will scroll to select the last process.
- Ctrl-A, ^: This will scroll left to the beginning of the line.
- Ctrl-E, $: This will scroll right to the end of the line.
- Space: This will untag or tag a process. Commands like ’kill’ will apply on the tagged processes and not on the currently highlighted one.
- U: This will remove all tags applied by the Space key.
- s: This will trace process system calls.
- l: This will show open files for a process. Pressing this key displays the list of file descriptors opened by the process if lsof(1) is installed.
Function keys while in htop:
- F1, h, ?: This will open the help screen
- F2, S: This will show the setup screen, where you can configure the meters displayed at the top, set display options, choose a color scheme, and select columns to display and in which order.
- F3, /: This will Incrementally search the command lines. In the search mode, pressing F3 again cycles through to the next match. F3 Esc will exit the search.
- F4, \: Use this for Incremental process filtering. Enter the Filter option again, then press Esc to cancel filtering.
- F5, t: This will display processes in a tree view. Works as a toggle; pressing F5 again will show the previous view.
- F6: This will select a new field for sorting. The selected field is highlighted in the header.
- F7, ]: Decrement the nice value of process(es). This increases the process’s priority and can only be done by the superuser.
- F8, [: This will increase the nice value of process(es), resulting in a decrease in process’s priority.
- F9, k: This will kill processes by sending a signal chosen by the user from a menu.
- F10, q: This will quit htop.
Other interactive commands used while in htop:
- I: This will change the sort order to increasing or decreasing.
- +, -: This will expand or collapse subtrees when in tree view mode.
- a: This will set CPU affinity when in a multiprocessor machine, marking which CPUs a process should use.
- u: This will show only processes for a specified user.
- M: Use this option to sort by memory usage.
- P: To sort by processor usage, use this option.
- T: This is used to sort by time.
- F: This is used for following a specific process. The process will be unfollowed by pressing a movement key.
- K: This will toggle the display of kernel threads.
- H: This will toggle the display of user threads.
- p: This will show the full paths to running programs. This is a toggle key.
- Ctrl-L : Refresh: This will redraw the screen and recalculate values.
- Numbers : PID search: The selection highlight will be moved to a process by typing in its process ID.
All you need is a Linux OS with htop and a few processes you can use the htop with.
How to Use the htop Command on Linux?
Now that you have all the necessary information, let’s dive in and learn how to use the htop command on Linux.
Run htop Command
To run Htop from the command line, use the syntax below:
Basically, there are two parts in the output, a header at the top with the summary information and data details below, one process per row. There are two columns for the header, the left, and the right. As you can see in the screenshot below, you will have graphic meters and text counters.
htop Usage Pane
The top-left panel corresponds to CPU per core, Memory, and Swap usage.
Here you can see that we have two CPU cores with a 100% utilization for the 2nd core and memory usage is 1.36 GB out of 3.71 GB.
htop Task Statistics Pane
The top-right panel shows the task statistics.
To interpret the sample output, 126 represents the number of current processes, and 232 threads handle these processes. Among these 126 tasks, two are running.
htop Process Information
In the main part of
htop are the detailed information for each process in the system.
- PID – Unique number/ID for the process.
- USER – The process owner.
- PRI – The kernel priority for the process.
- NI – The process priority by the USER. (Lower priority = Higher Nice Value).
- VIRT – Virtual Memory consumed by the process.
- RES – Resident Memory is the proportion of RAM the process is using.
- SHR – The amount of shared memory being consumed.
- S – The process state, R = running, S = Sleeping, D = Disk Sleep(uninterruptible), Z = Zombie(waiting for parent to exit), T = Traced or Suspended, and W = Paging.
- CPU% – CPU used by the process.
- MEM% – Memory consumed by the process.
- TIME+ – The period of time since the process started.
- Command – The command that initiated the process.
In this tutorial, we looked at what the htop command is all about. We’ve also learned how the htop command is used on Linux and how to interpret the information it shows.
If this guide helped you, please share it. ?