Powerful process viewer: htop

When it comes to system monitoring and task management tools, htop is a powerful and feature-rich option. It is an interactive process viewer that can graphically display system resource usage. This article will introduce the usage skills of htop and provide some examples to help you better understand and use this tool.

Introduction to htop

htop can interactively display system processes and resource usage in the terminal. It provides more functionality than the traditional top command and presents information in a colorful and intuitive graphical interface. Here are some of htop's features:

  • Real-time monitoring: htop displays the usage of system resources in real time, including CPU, memory, disk and network.
  • User-friendly interface: htop uses a colorful and intuitive interface to display process lists and system information.
  • Interactive operation: htop supports the use of mouse and keyboard for interaction, and can easily perform operations such as sorting, filtering and searching.
  • Feature-rich: htop provides many features, such as process tree view, process priority setting and process termination, etc.

Let's now dive into the mechanics of using htop and walk through some examples to demonstrate its capabilities.

Install and start htop

First, make sure you have htop installed on your system. For most Linux distributions, it can be installed using a package manager. For example, on Ubuntu, it can be installed with:

$ sudo apt-get install htop

Once installed, you can start htop by typing the command in Terminal htop.

htop parameter description

  • -d, --delay=SEC: Set the refresh delay, in seconds. Use this parameter to adjust how often htop is updated. For example, htop -d 5the information will be refreshed every 5 seconds.

  • -p, --pid=PID: Display information about the specified process. By specifying the PID of the process, you can directly view the resource usage of a specific process. For example, htop -p 1234information for a process with PID 1234 is displayed.

  • -u, --user=USERNAME: Only show processes with the specified username. Use this parameter to filter and display only processes belonging to a specific user. For example, htop -u johnonly processes belonging to user "john" will be displayed.

  • -s, --sort-key=COLUMN: Sort by the specified column. Processes can be sorted according to a specific column by specifying the column name. For example, htop -s CPU%processes are sorted by CPU usage.

  • -h, --highlight-threads: Highlight the thread. Use this parameter to highlight threads to make it easier to distinguish processes from threads.

  • --no-color: Disable colored output. If your terminal does not support color display or you prefer no color output, you can use this parameter to disable color output.

  • -C, --no-columns: Disable column headers. Use this parameter to disable the display of column headers and only show the process list and bottom info bar.

  • -h, --help: Display help information. Use this parameter to view htop's command-line options and parameter descriptions.

Basic interface of htop

After starting htop, you will see an interface similar to the following:

htop 2.2.0 - (C) 2004-2019 Hisham Muhammad
...

htop's interface consists of several areas, including the title bar, process list, and bottom information bar. You can use the arrow keys on the keyboard and the mouse to navigate and interact.

htop uses different colors to identify different processes and resource usage to provide a more intuitive visual representation. Here are some of the colors used in htop and their meanings:

  • Normal color : Most processes are displayed in normal color, indicating that resource usage is within the normal range.

  • Highlight color : Some special processes will be displayed in highlight color to highlight their importance or particularity.

  • Dim color : Some processes are shown in a dimmed color to indicate they are hibernating or sleeping.

  • Bold color : Some processes are displayed in bold to indicate that they are currently active processes.

  • Purple : Purple indicates kernel threads, threads that run in kernel space.

  • Blue : Blue indicates virtual memory mapping.

  • Green : Green indicates user-level tasks.

  • Yellow : Yellow indicates system-level tasks.

  • Red : Red indicates kernel-level tasks.

  • Light blue : Light blue indicates I/O waiting.

  • Bright Green : Bright green indicates that the CPU is waiting.

  • Bright red : Bright red indicates virtual memory swapping.

  • Gray : Gray indicates threads.

Note that the color display may vary depending on terminal settings, themes or profiles. You can customize it according to your preferences and needs. If you wish to disable the color display, you can start htop with --no-colorthe parameter.

htop process information

  1. PID : Process ID, which uniquely identifies each process.

  2. USER : The user who owns the process.

  3. PR : The priority of the process.

  4. NI : The nice value of the process, used to adjust the priority of the process.

  5. VIRT : The amount of virtual memory used by the process.

  6. RES : The physical memory size occupied by the process.

  7. SHR : shared memory size.

  8. S : The state of the process, such as running (R), sleeping (S), zombie (Z), etc.

  9. %CPU : The current CPU usage of the process.

  10. %MEM : The current memory usage of the process.

  11. TIME+ : The cumulative running time of the process on the CPU.

  12. COMMAND : The command line of the process.

In addition to these common process information, htop also provides some other optional column information. You can enter the setting interface by pressing the F2 key and select the "Columns" option to customize the displayed column information.

Here are some other common column information:

  • PPID : Parent process ID.

  • THCNT : The number of threads of the process.

  • PGRP : Process group ID.

  • TTY : The terminal device to which the process is connected.

  • UID : User ID.

  • GID : Group ID.

  • WCHAN : The kernel function that the process is currently waiting for.

  • F : The mark of the process (such as foreground process, background process).

These process information can help you monitor and understand the processes running on your system and their resource usage. You can sort and filter columns as needed for better analysis and process management.

sort process list

htop sorts processes by CPU usage by default. However, you can sort according to your needs. The following are some commonly used sorting methods and their corresponding shortcut keys:

  • Sort by CPU usage: Press F6the key, then select %CPUthe option.
  • Sort by memory usage: Press F6the key, then select %MEMan option.
  • Sort by Process ID: Press F6the key, then select PIDthe option.

You can also F5switch between different process viewing modes, such as tree mode, thread mode, and user mode, by pressing the key.

Example:

Assuming you want to sort by memory usage, you can press F6the key and select %MEMthe option. In this way, the list of processes will be displayed sorted by memory usage from high to low.

filter process list

If you are only interested in specific processes or keywords, htop provides a filtering function that can help you filter the process list. Press F4the key, enter the keyword to filter on the command line, and press the Enter key. Only processes matching the keyword will be displayed in the list.

Example:

Assuming you only want to see processes named "nginx", you can press F4the key, type "nginx" in the filter input box, and press Enter. Now, only processes containing the "nginx" keyword will be displayed in the list.

kill process

In htop, you can F9kill selected processes by pressing the key. Select the process you want to kill and press F9the key, htop will ask you to confirm that you want to kill the process.

Example:

Suppose you want to kill a process that is hogging too many resources. You can navigate to the process with the arrow keys and press F9the key. htop will then ask you to confirm that you want to kill the process. Press the Enter key and the process will be terminated.

Set options for htop

htop allows you to customize its behavior and appearance. Press F2the key, you will enter the setting interface of htop. Here you can change the color scheme, sorting options, display settings, and more.

Example:

Suppose you wish to change htop's color scheme to better suit your terminal setup. You can press F2the key, then use the arrow keys and the Enter key to browse and select different color schemes.

View help documentation

If you are not familiar with some functions of htop or have forgotten the shortcut keys, you can press F1the key to view the help documentation of htop. Help files provide detailed instructions on various functions and operations.

These are some htop usage tips and examples. By mastering these techniques, you can better utilize htop to monitor and manage system processes.

in conclusion

htop is a powerful and easy-to-use system monitoring and task management tool. It provides real-time system resource monitoring, interactive interface and many useful functions.

Guess you like

Origin blog.csdn.net/weixin_43025343/article/details/131645273