11人参与 • 2025-07-22 • Linux
可以显示系统的内存使用情况
[root@ypcvm ~]# free total used free shared buff/cache available mem: 9383776 294096 8829236 11972 260444 8837612 swap: 2097148 0 2097148
默认单位是:kb
第一列:
mem
: 表示物理内存swap
:表示硬盘上交换分区的使用情况total
: 总内存used
:已使用的内存free
:空闲的内存shared
:共享内存buff
/cache
:缓冲区和缓存available
:可用内存free
内存:这是系统中完全未被使用的内存数量available
内存:它更接近于可用内存,系统中可以立即分配给进程的内存数量,它包括free内存和一部分缓存的内存以可读的格式显示信息,如kb、mb、gb等
[root@ypcvm ~]# free -h total used free shared buff/cache available mem: 8.9g 289m 8.4g 11m 254m 8.4g swap: 2.0g 0b 2.0g [root@ypcvm ~]#
最后一行显示总计行
[root@ypcvm ~]# free -t total used free shared buff/cache available mem: 9383776 296324 8826800 11964 260652 8835300 swap: 2097148 0 2097148 total: 11480924 296324 10923948
total
:总计行实时地显示进程的状态,可以通过按上下箭头来翻滚查看需要查找的进程信息
也可以使虚拟机处于连接状态,不自动断开
[root@ypcvm ~]# top top - 14:36:29 up 1:03, 2 users, load average: 0.03, 0.04, 0.05 tasks: 110 total, 2 running, 108 sleeping, 0 stopped, 0 zombie %cpu(s): 0.0 us, 0.3 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st kib mem : 9383776 total, 8691232 free, 377512 used, 315032 buff/cache kib swap: 2097148 total, 2097148 free, 0 used. 8734152 avail mem pid user pr ni virt res shr s %cpu %mem time+ command 1 root 20 0 46092 6660 4176 s 0.0 0.1 0:01.49 systemd 2 root 20 0 0 0 0 s 0.0 0.0 0:00.00 kthreadd 4 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.20 ksoftirqd/0 7 root rt 0 0 0 0 s 0.0 0.0 0:00.00 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.57 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.03 watchdog/0 13 root 20 0 0 0 0 s 0.0 0.0 0:00.00 kdevtmpfs 14 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 netns 15 root 20 0 0 0 0 s 0.0 0.0 0:00.00 khungtaskd 16 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 writeback 17 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 kintegrityd 18 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 bioset 19 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 bioset 20 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 bioset 21 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 kblockd 22 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 md 23 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 edac-poller 24 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 watchdogd 30 root 20 0 0 0 0 s 0.0 0.0 0:00.00 kswapd0 31 root 25 5 0 0 0 s 0.0 0.0 0:00.00 ksmd 1524 root 20 0 1129720 59660 22144 s 0.0 0.6 0:01.11 dockerd
列出了一部分 下面还有
第二行:进程统计信息
110 total, 2 running, 108 sleeping, 0 stopped, 0 zombie
系统现在共有110个进程,其中处于运行中的有2个,108个在休眠,停止状态的有0个,僵尸状态的有0个
2 users:登录系统的用户数 root 以及 还有一个自己建立的用户
计算某个进程所占的物理内存大小:res-shr
来控制top命令结果的显示方式
command
:会显示完整[root@ypcvm ~]# top -c top - 14:58:00 up 1:24, 2 users, load average: 0.06, 0.04, 0.05 tasks: 108 total, 2 running, 106 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 : 9383776 total, 8693936 free, 374796 used, 315044 buff/cache kib swap: 2097148 total, 2097148 free, 0 used. 8736872 avail mem pid user pr ni virt res shr s %cpu %mem time+ command 968 root 20 0 305284 6380 5004 s 0.3 0.1 0:07.63 /usr/bin/vmtoolsd 1966 root 20 0 0 0 0 r 0.3 0.0 0:00.53 [kworker/0:2] 1 root 20 0 46092 6660 4176 s 0.0 0.1 0:01.53 /usr/lib/systemd/systemd --switched-root --syste+ 2 root 20 0 0 0 0 s 0.0 0.0 0:00.00 [kthreadd] 4 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.27 [ksoftirqd/0] 7 root rt 0 0 0 0 s 0.0 0.0 0:00.00 [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.60 [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.04 [watchdog/0] 13 root 20 0 0 0 0 s 0.0 0.0 0:00.00 [kdevtmpfs] 14 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 [netns] 15 root 20 0 0 0 0 s 0.0 0.0 0:00.00 [khungtaskd] 16 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 [writeback] 17 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 [kintegrityd] 18 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 [bioset] 19 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 [bioset] 20 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 [bioset] 21 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 [kblockd] 22 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 [md] 23 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 [edac-poller] 24 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 [watchdogd] 30 root 20 0 0 0 0 s 0.0 0.0 0:00.00 [kswapd0] 31 root 25 5 0 0 0 s 0.0 0.0 0:00.00 [ksmd] 32 root 39 19 0 0 0 s 0.0 0.0 0:00.10 [khugepaged] 33 root 0 -20 0 0 0 s 0.0 0.0 0:00.00 [crypto] 1524 root 20 0 1129720 59660 22144 s 0.0 0.6 0:01.20 /usr/bin/dockerd -h fd:// --containerd=/run/containerd/containerd.sock -h tcp://0.0.0.0:2375 -h unix://var+
已知docker的进程id为1524
[root@ypcvm ~]# ps -ef|grep docker root 1524 1 0 13:33 ? 00:00:01 /usr/bin/dockerd -h fd:// --containerd=/run/containerd/containerd.sock -h tcp://0.0.0.0:2375 -h unix://var/run/docker.sock root 1991 1912 0 15:04 pts/1 00:00:00 grep --color=auto docker
[root@ypcvm ~]# top -p 1524 top - 15:03:33 up 1:30, 2 users, load average: 0.01, 0.03, 0.05 tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie %cpu(s): 0.0 us, 0.3 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st kib mem : 9383776 total, 8693748 free, 374968 used, 315060 buff/cache kib swap: 2097148 total, 2097148 free, 0 used. 8736692 avail mem pid user pr ni virt res shr s %cpu %mem time+ command 1524 root 20 0 1129720 59660 22144 s 0.0 0.6 0:01.21 dockerd
pid user pr ni virt res shr s %cpu %mem time+ command 1486 root 20 0 1137916 60260 22552 s 0.0 0.6 0:00.36 dockerd 1523 root 20 0 1137916 60260 22552 s 0.0 0.6 0:00.07 dockerd 1524 root 20 0 1137916 60260 22552 s 0.0 0.6 0:00.01 dockerd 1525 root 20 0 1137916 60260 22552 s 0.0 0.6 0:00.00 dockerd 1529 root 20 0 1137916 60260 22552 s 0.0 0.6 0:00.21 dockerd 1530 root 20 0 1137916 60260 22552 s 0.0 0.6 0:00.12 dockerd 1531 root 20 0 1137916 60260 22552 s 0.0 0.6 0:00.14 dockerd 1532 root 20 0 1137916 60260 22552 s 0.0 0.6 0:00.00 dockerd 1533 root 20 0 1137916 60260 22552 s 0.0 0.6 0:00.00 dockerd 1534 root 20 0 1137916 60260 22552 s 0.0 0.6 0:00.00 dockerd 1535 root 20 0 1137916 60260 22552 s 0.0 0.6 0:00.00 dockerd 1536 root 20 0 1137916 60260 22552 s 0.0 0.6 0:00.00 dockerd
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论