top 命令用于查看系统的CPU、内存、运行时间、交换分区、执行的线程等信息。通过 top 命令可以有效的发现系统的缺陷出在哪里。是内存不够、CPU处理能力不够、IO读写过高…. 同时可以实时显示 process 的动态。
使用权限:所有使用者。
<p><pre> <code class="language-bash"><span class="o">[</span>root@localhost wbxbuilds<span class="o">]</span><span class="c1"># top</span>
top - 01:52:19 up <span class="m">32</span> days, 15:18, <span class="m">1</span> user, load average: 0.03, 0.06, 0.10
Tasks: <span class="m">206</span> total, <span class="m">1</span> running, <span class="m">205</span> sleeping, <span class="m">0</span> stopped, <span class="m">0</span> zombie
%Cpu<span class="o">(</span>s<span class="o">)</span>: 0.6 us, 0.3 sy, 0.0 ni, 97.5 id, 1.6 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : <span class="m">8010512</span> total, <span class="m">1043328</span> free, <span class="m">3339404</span> used, <span class="m">3627780</span> buff/cache
KiB Swap: <span class="m">3145724</span> total, <span class="m">3142272</span> free, <span class="m">3452</span> used. <span class="m">4226060</span> avail Mem </code></pre></p>
Top 输出详解
<p><pre> <code class="language-bash"><span class="c1"># top 命令第一行</span>
top - 01:52:19 up <span class="m">32</span> days, 15:18, <span class="m">1</span> user, load average: 0.03, 0.06, 0.10</code></pre></p>
注意:load average 数据是每隔 5 秒钟检查一次活跃的进程数,然后按特定算法计算出的数值。如果这个数除以逻辑 CPU 的数量,结果高于 5 的时候就表明系统在超负荷运转了。
<p><pre> <code class="language-bash"><span class="c1"># top 命令第二行</span>
Tasks: <span class="m">206</span> total, <span class="m">1</span> running, <span class="m">205</span> sleeping, <span class="m">0</span> stopped, <span class="m">0</span> zombie</code></pre></p>
<p><pre> <code class="language-bash"><span class="c1"># top 命令第三行, cpu 状态</span>
%Cpu<span class="o">(</span>s<span class="o">)</span>: 0.6 us, 0.3 sy, 0.0 ni, 97.5 id, 1.6 wa, 0.0 hi, 0.0 si, 0.0 st</code></pre></p>
依次对应如下:
si 表示处理软中断消耗的时间。st: 只有 Linux 在作为虚拟机运行时 st 才是有意义的。它表示虚机等待 CPU 资源的时间(虚机分到的是虚拟 CPU,当需要真实的 CPU 时,可能真实的 CPU 正在运行其它虚机的任务,所以需要等待)。
<p><pre> <code class="language-bash"><span class="c1"># top 命令第四行,内存状态</span>
KiB Mem : <span class="m">8010512</span> total, <span class="m">1043328</span> free, <span class="m">3339404</span> used, <span class="m">3627780</span> buff/cache
<span class="c1"># top 命令第五行,内存交换分区</span>
KiB Swap: <span class="m">3145724</span> total, <span class="m">3142272</span> free, <span class="m">3452</span> used. <span class="m">4226060</span> avail Mem </code></pre></p>
上述类似 Linuxfree指令展示的内存信息。
任务详情
<p><pre> <code class="language-text"> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
19021 rabbitmq 20 0 3389628 105812 4320 S 4.0 1.3 826:20.61 beam.smp
1124 root 20 0 582176 31204 14476 S 0.3 0.4 4:17.64 containerd
4954 root 20 0 5760308 965756 14436 S 0.3 12.1 21:14.08 java
22793 root 20 0 196836 45592 32860 S 0.3 0.6 56:26.12 consul
29271 root 20 0 157764 2344 1580 R 0.3 0.0 0:01.36 top
1 root 20 0 191020 4016 2572 S 0.0 0.1 0:49.52 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.89 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:01.00 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
7 root rt 0 0 0 0 S 0.0 0.0 0:02.14 migration/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root 20 0 0 0 0 S 0.0 0.0 7:12.66 rcu_sched
10 root rt 0 0 0 0 S 0.0 0.0 0:09.27 watchdog/0
11 root rt 0 0 0 0 S 0.0 0.0 0:07.77 watchdog/1</code></pre></p>
默认情况下这里会显示 12 列数据:
%CPU 表示进程使用 CPU 的百分比。%MEM 表示进程使用内存的百分比。TIME+ 表示进程累计使用的 CPU 时间。COMMAND 表示运行进程对应的程序。 |
|