Thoroughly understand the Linux htop command in one article

Mondo Technology Updated on 2024-02-18

The htop command is a Linux utility that displays key information about system processes. It can be seen as the Linux version of Windows Task Manager. htop is more of an interactive program, as it supports mouse and keyboard actions to switch between values and tabs.

Debian Ubuntu.

apt install htop
Fedora down.

dnf install htop
snap package installation.

snap install htop
Build and compile from source.

wgettar -zxvf 3.3.0.tar.gz

cd 3.3.0

./configure

make

make install

Compared with the traditional TOP of Linux, HTOP is more user-friendly. It allows users to interact with each other, supports color themes, scrolls through the list of processes horizontally or vertically, and supports mouse actions.

Htop Pros:

You can scroll through the list of processes horizontally or vertically so that you can see all the processes and the full command line.

On startup, faster than top.

You do not need to enter a process number to kill a process.

htop supports mouse operation.

TOP is more cumbersome.

TOP Cons:

Only keyboard operation is supported.

The display is also monotonous.

htop [-dcfhpustvh]
Command-line options.

-d, -delay=delay: The delay between updates, i.e., the time between each refresh of a process, in tenths of a second, e.g. 1 second for 10 10 and 10 for 10 10delayThe minimum value is 1 and the maximum value is 100, ifdelayIf the value is less than 1, it will be automatically changed to 1, and if it is greater than 100, it will be automatically changed to 100.

-c, -no-color --no-colour: Black and white mode, no color display.

-f, -filter=filter: By fixing the string filtering process, strings are not treated as regular expressions and are case-insensitive, and are used for multiple stringsSeparated.

-h, -help: Prints the help information.

-p, -pid=pid,pid...: Displays only the specified onespidProcess information, you can specify more than one, using a commaSeparated.

-s --sort-key column: Sort by field.

-u, -user=username|uid: Displays only the processes to which the specified user belongs, and can pass the user name or user ID.

-u, -no-unicode: Instead of Unicode, the graphics gauge uses ASCII characters.

-m, -no-mouse: Disables mouse control.

--readonly: Read-only mode, which disables all system and process changes.

-v, -version: Prints version information.

-t, -tree: displays the process list in a tree structure.

-h --highlight-changes=delay: Highlight new and old processes.

Interactive commands.

tab, shift-tab: Select the next Previous screen tab to display.

up, alt-k: Select (highlight) the previous process in the process list.

down, alt-j: Select (highlight) the next process in the list of processes.

left, alt-h: Scroll left to the list of processes.

right, alt-l: Scrolls the list of processes to the right.

pgup, pgdn: Scroll up or down the list of processes in one window, i.e. turn pages.

home: Scroll to the top of the process list and select the first process.

end: Scroll to the bottom of the process list and select the last process.

ctrl-a, ^: Scroll left to the beginning of the process field item.

ctrl-e, $: Scroll to the right to the end of the process field item.

space: Mark or unmark a process. Commands that can be manipulated by multiple processes, such as "kill", will be applied to the list of marked processes, rather than the currently highlighted process.

c: Marks the current process and its children. Commands that can be executed operate on multiple processes, such as "kill", will then be applied to the list of tagged processes instead of the current highlighted process.

u: Unmark all processes, including usagespacewithcTagged.

s: Trace process system call: if already installedstrace, pressing this key will attach it to the system call issued by the currently selected process to update this process in real time.

l: Displays the files opened by the process, if already installedlsof, pressing this key will invokelsof

w: Displays the command line of the selected process on a separate screen, wrapping it into multiple lines as needed.

x: Displays the active file lock for the selected process on a separate screen.

f1, h, ?: Skip to the help information page.

f2, s: Jump to the installation page, you can customize the ruler display, set the display specified options, select the color scheme, set the display of the specified fields, and the order of the fields.

f3, /: In search mode, loop matching,f3Find the next matchshift + f3Find the last match.

f4, \: filter the matched processes by fixed strings (non-regular expressions); When canceling the filter, enter the filter option again and pressesc;This filter is case-insensitive, and multiple filters are usedSeparated.

f5, t: A tree view that organizes processes by parent and lays out the relationships between them like a tree. Toggle this option to toggle between the tree view and the previously selected sorted view, note that selecting the sorted view exits the tree view.

f6, <: Select the fields you want to sort.

f7, ]: Increases the priority value of the selected process.

f8, [: Reduces the priority value of the selected process.

shift-f7, }: Increases the value of the automatic grouping priority of the selected process.

shift-f8, {: Reduces the auto-grouping priority value for the selected process.

f9, k: Kills a process, sends a signal that it is selected in the menu: a process or group of processes. If a process is flagged, a signal is sent to all flagged processes. If there are no tags, send to the currently selected process.

f10, q:Quit.

i: Inverts the sorting, and if the sort order increases, switches to decreasing or vice versa.

: In tree view mode, expand or collapse the subtree. When a subtree is collapsed, the "+ sign" is displayed on the left side of the process name. Pressing "*" will expand or collapse all.

A child node that does not have a PID of the parent node.

u: Displays only processes owned by the specified user.

n: PassedpidSort.

m: Sort by memory usage.

p: Sort by CPU usage.

t: Sort by time.

f: If the sort order causes the currently selected process to move in the list, make the selection bar follow it. This is useful for monitoring processes so that you can keep them on the screen at all times.

k: Hide kernel processes, which can be toggled between hiding and showing.

h: Hides user-level processes, which can be toggled between hiding and showing.

o: Hides the containerized process, which can be toggled between hiding and showing.

p: Displays the full path of the running program, which can be toggled between hiding and showing.

z: Pause to resume process updates, which can be switched.

m: Mergeexecommcmdlineto switch.

ctrl-l: Refreshes the list of processes.

[numbers]: PassedpidSearch for the specified process and highlight it.

CPU and memory usage.

The upper left panel corresponds to CPU and memory usage, 1-4, representing the number of CPU cores, the histogram depicts the number and type of processes using each core, and the values on the histogram represent the percentage of each core consumed.

Color coding of the CPU.

green: the amount of CPU consumed by the user process.

red: the amount of CPU consumed by the system process.

grey: The number of CPUs used for I/O/O based processes.

blue: the number of CPUs consumed by low-priority processes.

Color coding of memory.

green: the percentage of RAM used to run processes in the system.

blue: the percentage of RAM consumed by the buffer page.

orange yellow: The percentage of RAM used for cache memory.

Task statistics.

The upper right panel shows the task statistics section.

Represents the number of current task processes in the system.

Thisprocesses are made up ofthreads (thr) processing.

Inthreads, there iskernel threads (KTHR).

In, only one process is running.

Since this is a quad-core system, the maximum load isRepresents the average load in the last minute; Represents the average load in the last 5 minutes; Represents the average load of the last 15 minutes.

uptime indicates the length of time since the last system reboot.

Process information description.

PID (Process ID): The ID of the process.

user: the owner of the process.

pri (priority): The priority of the kernel over the process.

ni (nice value): The priority of the process viewed by the userniceThe higher the value, the lower the priority.

virt (virtual memory): The amount of virtual memory consumed by the process.

RES (Resident Memory): The proportion of RAM that is being used by the process.

SHR (Shared Memory): the amount of shared memory occupied by the task.

S (status): process status, S (hibernating), R (running).

CPU%: the percentage of CPU consumed by the process.

mem%: the percentage of memory consumed by the process.

time+: the duration of the process.

command: The complete command of the process that contains the program name and parameters.

General usage.

htop
Displays the process for the specified user.

htop -u root
Display specifiedpidprocess.

htop -p 123,456,789
Specify the field sorting.

htop -s percent_mem

Description: Sorted by percentage of memory used.

Set the time interval for process refresh.

htop -d 10

Note: Set the interval to 1 second, that is, 10 10

Black & White Mode.

htop -c
Displays a tree-like structure.

htop -t

Related Pages