Linux进程管理——查看内存的工具
一查看内存的工具vmstat
vmstat命令:虚拟内存信息
vmstat [options] [delay [count]]
vmstat 2 5
[root@centos72 ~]# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 0 610224 2076 279392 0 0 32 9 316 55 8 19 73 1 0 [root@centos72 ~]# rpm -q vmstat package vmstat is not installed [root@centos72 ~]# type vmstat vmstat is hashed (/usr/bin/vmstat)
[root@centos72 ~]# free
total used free shared buff/cache available
Mem: 997980 106532 609936 7832 281512 705116 Swap: 2097148 0 2097148
详细选项:
procs:
r:可运行(正运行或等待运行)进程的个数,和核心数有关
b:处于不可中断睡眠态的进程个数(被阻塞的队列的长度)
memory:
swpd: 交换内存的使用总量
free:空闲物理内存总量
buffer:用于buffer的内存总量
cache:用于cache的内存总量
注意buffer和cache的区别
swap:
si:从磁盘交换进内存的数据速率(kb/s)
so:从内存交换至磁盘的数据速率(kb/s)
查看帮助文档
Swap
si: Amount of memory swapped in from disk (/s).
so: Amount of memory swapped to disk (/s).
io:
bi:从块设备读入数据到系统的速率(kb/s),也就是出磁盘进内存
bo: 保存数据至块设备的速率,也就是进磁盘出内存
IO
bi: Blocks received from a block device (blocks/s).
bo: Blocks sent to a block device (blocks/s).
设置1秒执行一次
[root@centos72 ~]# vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 0 758312 2076 134872 0 0 56 5 68 82 0 0 98 2 0 0 0 0 758288 2076 134872 0 0 0 0 55 41 0 0 100 0 0 0 0 0 758288 2076 134872 0 0 0 0 52 46 0 0 100 0 0 0 0 0 758288 2076 134872 0 0 0 0 52 45 0 0 100 0 0 0 0 0 758288 2076 134872 0 0 0 0 56 48 0 0 100 0 0 0 0 0 758288 2076 134872 0 0 0 0 45 33 0 0 100 0 0 0 0 0 758288 2076 134872 0 0 0 0 50 42 0 0 100 0 0
top命令也有一样的选项
top - 00:50:39 up 49 min, 2 users, load average: 0.00, 0.01, 0.05 Tasks: 104 total, 1 running, 103 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 997980 total, 757148 free, 103336 used, 137496 buff/cache KiB Swap: 2097148 total, 2097148 free, 0 used. 733212 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 20 0 193316 6412 4080 S 0.0 0.6 0:01.47 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:00.02 ksoftirqd/0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 6 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/u256:0 7 root rt 0 0 0 0 S 0.0 0.0 0:00.04 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 0:00.33 rcu_sched 10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 lru-add-drain 11 root rt 0 0 0 0 S 0.0 0.0 0:00.01 watchdog/0 12 root rt 0 0 0 0 S 0.0 0.0 0:00.01 watchdog/1 13 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/1 14 root 20 0 0 0 0 S 0.0 0.0 0:00.01 ksoftirqd/1 16 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/1:0H 18 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
system:
in: interrupts 中断速率,包括时钟
cs: context switch 进程切换速率,切换高不好
这和学习一样,要集中精力才会效率高
cpu:
us:Time spent running non-kernel code
sy: Time spent running kernel code
id: Time spent idle. Linux 2.5.41前,包括IO-wait time.
wa: Time spent waiting for IO. 2.5.41前,包括in idle.
st: Time stolen from a virtual machine. 2.6.11前, unknown.
开启一个进程,可以看到刚开始是出内存的多
因为内存空间满了就要里面的内容导到交换分区里面
[root@centos72 ~]# vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st 3 0 0 138112 2076 135496 0 0 15 1 40 38 0 0 99 0 0 0 7 135944 48976 0 67688 128 227088 9540 227089 5203 777 0 10 14 76 0 0 8 280072 48764 0 59576 224 63932 6664 63948 1314 244 0 3 0 97 0 0 7 317960 48800 0 63960 8 26792 256 26792 646 241 0 1 0 99 0 0 8 355080 64672 0 65012 276 37012 1348 37012 1428 218 0 3 7 91 0 0 8 402696 64132 0 65596 96 47628 260 47628 210 60 0 2 0 99 0 0 10 429832 49148 0 65448 120 27140 304 27140 248 101 0 1 0 99 0 0 10 489224 48824 0 58192 128 91312 8772 91312 2527 384 0 5 0 95 0 1 9 567296 72648 0 61268 96 46084 220 46084 355 164 0 1 0 99 0 4 9 582152 48704 0 60316 280 14696 676 14696 12712 295 0 33 0 67 0 4 9 590344 48880 0 61336 32 8456 1096 8456 102 50 0 9 0 91 0 8 9 618240 50096 0 60216 52 28704 316 28704 902 134 0 11 0 89 0 14 10 651520 48860 0 61432 32 32524 32 32524 1077 193 0 14 0 86 0 2 12 686080 48812 0 61740 32 34676 144 34676 702 140 0 9 62 29 0