htop 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

htop 命令安装:


-bash/zsh: htop: command not found

#Windows (WSL2)
sudo apt-get update sudo apt-get install htop

#CentOS
yum install htop

#Debian
apt-get install htop

#Ubuntu
apt-get install htop

#Alpine
apk add htop

#Arch Linux
pacman -S htop

#Kali Linux
apt-get install htop

#Fedora
dnf install htop

#OS X
brew install htop

#Raspbian
apt-get install htop

#Dockerfile
dockerfile.run/htop

#Docker
docker run cmd.cat/htop htop

htop 命令补充说明:


htop 是一个跨平台的交互式进程查看器。 它是一个文本模式应用程序(用于控制台或 X 终端)并且需要 ncurses。

支持垂直和水平滚动,因此您可以看到系统上运行的所有进程,以及它们的完整命令行,以及将它们视为进程树,选择多个进程并同时对它们进行操作。无需输入进程的 PID 即可完成与进程相关的任务(killing、renicing)。


htop -t 执行后,UI 如下:

  CPU[||||                                                                                2.7%]   Tasks: 35, 124 thr; 1 running
  Mem[|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||394M/991M]   Load average: 0.03 0.03 0.05 
  Swp[                                                                                   0K/0K]   Uptime: 996 days(!), 04:28:55

  PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
    1 root       20   0  195M  3424  1476 S  0.0  0.3  3h40:59 /usr/lib/systemd/systemd --system --deserialize 22
30789 root       20   0 57268  2832  1456 S  0.0  0.3  0:00.47 ├─ nginx: master process /app/nginx/sbin/nginx
32426 nobody     20   0 57668  4056  2312 S  0.0  0.4  0:00.01 │  └─ nginx: worker process
28850 root       20   0  971M 17412  6412 S  0.0  1.7  0:57.44 ├─ /usr/libexec/snapd/snapd
28934 root       20   0  971M 17412  6412 S  0.0  1.7  0:17.13 │  ├─ /usr/libexec/snapd/snapd
28891 root       20   0  971M 17412  6412 S  0.0  1.7  0:13.67 │  ├─ /usr/libexec/snapd/snapd
28863 root       20   0  971M 17412  6412 S  0.0  1.7  0:07.52 │  ├─ /usr/libexec/snapd/snapd
28857 root       20   0  971M 17412  6412 S  0.0  1.7  0:17.05 │  ├─ /usr/libexec/snapd/snapd
28856 root       20   0  971M 17412  6412 S  0.0  1.7  0:00.05 │  ├─ /usr/libexec/snapd/snapd
28853 root       20   0  971M 17412  6412 S  0.0  1.7  0:00.00 │  ├─ /usr/libexec/snapd/snapd
28852 root       20   0  971M 17412  6412 S  0.0  1.7  0:00.00 │  ├─ /usr/libexec/snapd/snapd
28851 root       20   0  971M 17412  6412 S  0.0  1.7  0:01.93 │  └─ /usr/libexec/snapd/snapd
28187 root       20   0  412M 11416     0 S  0.0  1.1  4h19:30 ├─ /Data/apps/memcache/bin/memcached -d -m 2 -u root -l 127.0.0.1 -p 11211 -c 1000 -P /tmp/memcached.pid
28196 root       20   0  412M 11416     0 S  0.0  1.1  0:00.00 │  ├─ /Data/apps/memcache/bin/memcached -d -m 2 -u root -l 127.0.0.1 -p 11211 -c 1000 -P /tmp/memcached.pid
28195 root       20   0  412M 11416     0 S  0.0  1.1  3h13:37 │  ├─ /Data/apps/memcache/bin/memcached -d -m 2 -u root -l 127.0.0.1 -p 11211 -c 1000 -P /tmp/memcached.pid
28194 root       20   0  412M 11416     0 S  0.0  1.1  0:01.20 │  ├─ /Data/apps/memcache/bin/memcached -d -m 2 -u root -l 127.0.0.1 -p 11211 -c 1000 -P /tmp/memcached.pid
28193 root       20   0  412M 11416     0 S  0.0  1.1  0:00.00 │  ├─ /Data/apps/memcache/bin/memcached -d -m 2 -u root -l 127.0.0.1 -p 11211 -c 1000 -P /tmp/memcached.pid
28192 root       20   0  412M 11416     0 S  0.0  1.1  0:00.12 │  ├─ /Data/apps/memcache/bin/memcached -d -m 2 -u root -l 127.0.0.1 -p 11211 -c 1000 -P /tmp/memcached.pid
28191 root       20   0  412M 11416     0 S  0.0  1.1  0:00.13 │  ├─ /Data/apps/memcache/bin/memcached -d -m 2 -u root -l 127.0.0.1 -p 11211 -c 1000 -P /tmp/memcached.pid
28190 root       20   0  412M 11416     0 S  0.0  1.1  0:00.12 │  ├─ /Data/apps/memcache/bin/memcached -d -m 2 -u root -l 127.0.0.1 -p 11211 -c 1000 -P /tmp/memcached.pid
28189 root       20   0  412M 11416     0 S  0.0  1.1  0:00.13 │  ├─ /Data/apps/memcache/bin/memcached -d -m 2 -u root -l 127.0.0.1 -p 11211 -c 1000 -P /tmp/memcached.pid
28188 root       20   0  412M 11416     0 S  0.0  1.1 22:51.18 │  └─ /Data/apps/memcache/bin/memcached -d -m 2 -u root -l 127.0.0.1 -p 11211 -c 1000 -P /tmp/memcached.pid
28075 root       20   0  110M  1776   748 S  0.0  0.2  5:50.76 ├─ /usr/sbin/sshd -D
27363 root       20   0  151M  5284  3972 S  0.0  0.5  0:00.08 │  └─ sshd: root@pts/0
27366 root       20   0  113M  3184  1608 S  0.0  0.3  0:00.04 │     └─ -bash
 3305 root       20   0  120M  2788  1496 R  0.4  0.3  0:00.02 │        └─ htop -t
21579 root       19  -1 1290M 26932  6108 S  0.0  2.7 46h45:14 ├─ /usr/bin/python2 -s /usr/bin/fail2ban-server -xf start
21593 root       20   0 1290M 26932  6108 S  0.0  2.7  2h04:13 │  ├─ /usr/bin/python2 -s /usr/bin/fail2ban-server -xf start
21592 root       20   0 1290M 26932  6108 S  0.0  2.7  2h29:00 │  ├─ /usr/bin/python2 -s /usr/bin/fail2ban-server -xf start
21591 root       20   0 1290M 26932  6108 S  0.0  2.7  2h12:52 │  ├─ /usr/bin/python2 -s /usr/bin/fail2ban-server -xf start
21590 root       20   0 1290M 26932  6108 S  0.0  2.7  2h30:48 │  ├─ /usr/bin/python2 -s /usr/bin/fail2ban-server -xf start
21589 root       20   0 1290M 26932  6108 S  0.0  2.7  2h47:04 │  ├─ /usr/bin/python2 -s /usr/bin/fail2ban-server -xf start
21588 root       20   0 1290M 26932  6108 S  0.0  2.7  8h20:33 │  ├─ /usr/bin/python2 -s /usr/bin/fail2ban-server -xf start
21582 root       20   0 1290M 26932  6108 S  0.4  2.7 12h42:40 │  ├─ /usr/bin/python2 -s /usr/bin/fail2ban-server -xf start
 3046 root       20   0 1290M 26932  6108 S  0.0  2.7  0:00.17 │  └─ /usr/bin/python2 -s /usr/bin/fail2ban-server -xf start
21040 root       20   0 45044  1072   416 S  0.0  0.1  0:00.13 ├─ /usr/lib/systemd/systemd-udevd
 8250 root       10 -10  138M 18056  3972 S  1.8  1.8 11h23:09 ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8294 root       10 -10  138M 18056  3972 R  0.9  1.8  8h09:41 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8275 root       10 -10  138M 18056  3972 S  0.0  1.8  0:02.39 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8274 root       10 -10  138M 18056  3972 S  0.0  1.8  0:05.13 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8273 root       10 -10  138M 18056  3972 S  0.0  1.8  7:26.50 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8272 root       10 -10  138M 18056  3972 S  0.0  1.8  7:55.72 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8271 root       10 -10  138M 18056  3972 S  0.0  1.8  8:00.29 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8270 root       10 -10  138M 18056  3972 S  0.0  1.8  4:56.93 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8269 root       10 -10  138M 18056  3972 S  0.0  1.8  5:34.13 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8268 root       10 -10  138M 18056  3972 S  0.0  1.8  2:42.80 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8267 root       10 -10  138M 18056  3972 S  0.0  1.8  5:07.03 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8266 root       10 -10  138M 18056  3972 S  0.0  1.8  0:22.02 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8265 root       10 -10  138M 18056  3972 S  0.0  1.8 59:48.75 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8264 root       10 -10  138M 18056  3972 S  0.0  1.8  0:05.29 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8263 root       10 -10  138M 18056  3972 S  0.0  1.8  0:19.67 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8262 root       10 -10  138M 18056  3972 S  0.0  1.8  4:52.05 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8261 root       10 -10  138M 18056  3972 S  0.0  1.8  6:18.96 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8259 root       10 -10  138M 18056  3972 S  0.0  1.8  0:29.15 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8258 root       10 -10  138M 18056  3972 S  0.0  1.8  0:18.43 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8257 root       10 -10  138M 18056  3972 S  0.0  1.8  0:04.92 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8256 root       10 -10  138M 18056  3972 S  0.0  1.8 20:00.82 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8255 root       10 -10  138M 18056  3972 S  0.0  1.8  0:17.75 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8254 root       10 -10  138M 18056  3972 S  0.0  1.8 17:30.02 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8253 root       10 -10  138M 18056  3972 S  0.0  1.8  2:51.78 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8252 root       10 -10  138M 18056  3972 S  0.0  1.8  2:29.62 │  ├─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor
 8251 root       10 -10  138M 18056  3972 S  0.0  1.8  2:22.18 │  └─ /usr/local/aegis/aegis_client/aegis_11_55/AliYunDunMonitor

htop 命令语法:


htop [-dChustv]

htop 命令选项:


-d --delay=DELAY
      Delay between updates, in tenths of seconds

-C --no-color --no-colour
      Start htop in monochrome mode

-h --help
      Display a help message and exit

-p --pid=PID,PID...
      Show only the given PIDs

-s --sort-key COLUMN
      Sort by this column (use --sort-key help for a column list)

-u --user=USERNAME
      Show only the processes of a given user

-v --version
      Output version information and exit

-t --tree
      Show processes in tree view

htop 命令实例:


启动 htop:

htop

htop 按指定的 sort_item 对进程进行排序(使用 `htop --sort help` 获取可用选项):

htop --sort sort_item

启动 htop 显示特定用户拥有的进程:

htop --user username

运行 htop 时查看交互式命令:

?

htop 切换不同的 tab 标签:

tab

htop 的 help

htop --help

htop 命令扩展阅读:




htop 命令评论

共收录到 489Linux 命令