Linux Performance Analysis: htop Command Usage

Image sourced from: https://htop.dev/

htop is a command similar to top, but with more features and a friendlier interface. It can display real-time resource usage of various processes in the system, such as CPU usage, memory usage, etc. Below is a complete breakdown of the htop command:

When you run the htop command, you will see the following output:

  1  [|||||||                                       10.0%]     Tasks: 30, 60 thr; 2 running
  2  [||||||||                                      12.0%]     Load average: 0.29 0.33 0.47
  3  [|||||||                                       10.0%]     Uptime: 01:23:45
  4  [|||||||||                                     15.0%]
  Mem[|||||||||||||||||||||||||||||         1834/7980MB]
  Swp[                                              0/0MB]

PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command
1 root 20 0 225848 9480 6812 S 0.0 0.5 00:02.03 /sbin/init
2 root 20 0 0 0 0 S 0.0 0.0 00:00.01 [kthreadd]
3 root 20 0 0 0 0 S 0.0 0.0 00:00.50 [ksoftirqd/0]

Next, we will break down the output of the htop command line by line:

  1. First line:
  • 1, 2, 3, 4: indicate the CPU core numbers (if there are multiple cores).

  • [||||||| 10.0%]: the usage rate of each CPU core. This is a graphical progress bar representing CPU usage. In this example, the CPU1 usage rate is 10.0%.

  1. Second line:
  • Tasks: 30, 60 thr; 2 running: displays the number of processes and threads. There are 30 processes and 60 threads here, with 2 processes running.

  • Load average: 0.29 0.33 0.47: system average load (average values over the past 1 minute, 5 minutes, and 15 minutes).

  • Uptime: 01:23:45: system uptime.

  1. Third line:
  • Mem[||||||||||||||||||||||||||||| 1834/7980MB]: memory usage. This is a graphical progress bar representing memory usage. In this example, 1834MB is used, and the total memory is 7980MB.

  • Swp[ 0/0MB]: swap partition usage. This is a graphical progress bar representing swap partition usage. In this example, no swap partition is configured.

  1. Each subsequent line represents information for a process:
  • PID: process ID.

  • USER: the owner of the process.

  • PRI: process priority (smaller value means higher priority).

  • NI: the nice value of the process (-20 to 19, lower value means higher priority).

  • VIRT: total virtual memory used by the process (KiB).

  • RES: physical memory used by the process (resident set size, KiB).

  • SHR: shared memory used by the process (KiB).

  • S: process state (R: running, S: sleeping, T: traced/stopped, Z: zombie).

  • CPU%: CPU usage occupied by the process.

  • MEM%: percentage of physical memory occupied by the process.

  • TIME+: cumulative CPU time used by the process (hours:minutes:seconds).

  • Command: the name of the process startup command.

In the interactive interface of the htop command, you can use the following keys to perform operations:

  • F1 or h or ?: display help.

  • q or F10: exit htop.

  • F2 or S: settings interface, you can configure display options, colors, etc.

  • F3 or /: search for processes.

  • F4 or \: filter processes by user.

  • F5 or t: toggle tree view mode.

  • F6 or < or >: select sorting method.

  • F7 or [: lower the priority of the selected process (increase the nice value).

  • F8 or ]: raise the priority of the selected process (decrease the nice value).

  • F9 or k: kill the selected process.

  • Space: mark/unmark the selected process.

  • u: clear all marked processes.

Appendix

  • https://github.com/htop-dev/htop

This article was synced using Article Sync Assistant


This is a discussion topic separated from the original topic at https://juejin.cn/post/7368294440547794982