Linux 系统的内存管理工作中,内存使用情况的监控是十分重要的,在各种 Linux 发行版上你会找到许多这种工具。它们的工作方式多种多样,在这里,我们将会介绍如何安装和使用这样的一个名为 smem 的工具软件。

Smem工具的简介

Smem 是一款命令行下的内存使用情况报告工具,它能够给用户提供 Linux 系统下的内存使用的多种报告。和其它传统的内存报告工具不同的是,它有个独特的功能,可以报告 PSS【Proportional Set Size(按比例占用大小)】,这种内存使用量表示方法对于那些在虚拟内存中的应用和库更有意义。传统工具会将目光主要集中于读取 RSS,这种方法是以物理内存方案来衡量使用情况的标准方法,但是往往高估了应用程序的内存的使用情况。PSS 从另一个侧面,通过判定在虚拟内存中的应用和库所使用的“合理分享”的内存,来给出更可信的衡量结果。

Smem 这一工具的特点
 系统概览列表以进程、映射和用户来显示或者是过滤从 /proc 文件系统中得到数据从多个数据源配置显示的条目可配置输出单位和百分比易于配置列表表头和汇总从镜像文件夹或者是压缩的 tar 文件中获得数据快照内置的图表生成机制轻量级的捕获工具,可用于嵌入式系统
安装 Smem - Linux工具
安装条件:
现代内核 (版本号高于 2.6.27)较新的 Python 版本 (2.4 及以后版本)可选的 matplotlib 库用于生成图表

对于当今的大多数的 Linux 发行版而言,内核版本和 Python 的版本都能够满足需要,所以仅需要为生成良好的图表安装 matplotlib 库。

RHEL, CentOS 和 Fedora

首先启用 EPEL (Extra Packages for Enterprise Linux)软件源,然后按照下列步骤操作:

# yum install smem python-matplotlib python-tk
Debian 和 Ubuntu
$ sudo apt-get install smem
Linux Mint
$ sudo apt-get install smem python-matplotlib python-tk
Arch Linux

使用此"https://www.archlinux.org/packages/community/i686/smem/"的AUR 仓库。

Smem–Linux的使用
内存使用情况
$ sudo smemPID User     Command                         Swap      USS      PSS      RSS6367 tecmint  cat                                0      100      145     17846368 tecmint  cat                                0      100      147     16762864 tecmint  /usr/bin/ck-launch-session         0      144      165     17807656 tecmint  gnome-pty-helper                   0      156      178     18325758 tecmint  gnome-pty-helper                   0      156      179     19161441 root     /sbin/getty -8 38400 tty2          0      152      184     20521434 root     /sbin/getty -8 38400 tty5          0      156      187     20601444 root     /sbin/getty -8 38400 tty3          0      156      187     20601432 root     /sbin/getty -8 38400 tty4          0      156      188     21241452 root     /sbin/getty -8 38400 tty6          0      164      196     20642619 root     /sbin/getty -8 38400 tty1          0      164      196     21363544 tecmint  sh -c /usr/lib/linuxmint/mi        0      212      224     15401504 root     acpid -c /etc/acpi/events -        0      220      236     16043311 tecmint  syndaemon -i 0.5 -K -R             0      252      292     25563143 rtkit    /usr/lib/rtkit/rtkit-daemon        0      300      326     25481588 root     cron                               0      292      333     23441589 avahi    avahi-daemon: chroot helpe         0      124      334     16321523 root     /usr/sbin/irqbalance               0      316      343     2096585 root     upstart-socket-bridge --dae        0      328      351     18203033 tecmint  /usr/bin/dbus-launch --exit        0      328      360     21601346 root     upstart-file-bridge --daemo        0      348      371     17762607 root     /usr/bin/xdm                       0      188      378     23681635 kernoops /usr/sbin/kerneloops               0      352      386     2684344 root     upstart-udev-bridge --daemo        0      400      427     21322960 tecmint  /usr/bin/ssh-agent /usr/bin        0      480      485      9923468 tecmint  /bin/dbus-daemon --config-f        0      344      515     32841559 avahi    avahi-daemon: running [tecm        0      284      517     31087289 postfix  pickup -l -t unix -u -c            0      288      534     28082135 root     /usr/lib/postfix/master            0      352      576     28722436 postfix  qmgr -l -t unix -u                 0      360      606     28841521 root     /lib/systemd/systemd-logind        0      600      650     32762222 nobody   /usr/sbin/dnsmasq --no-reso        0      604      669     3288
....
查看用户进程占用内存情况

普通用户运行 smem,显示由该用户的进程的占用情况,并按照 PSS 的值升序排列。

$ smemPID User     Command                         Swap      USS      PSS      RSS6367 tecmint  cat                                0      100      145     17846368 tecmint  cat                                0      100      147     16762864 tecmint  /usr/bin/ck-launch-session         0      144      166     17803544 tecmint  sh -c /usr/lib/linuxmint/mi        0      212      224     15403311 tecmint  syndaemon -i 0.5 -K -R             0      252      292     25563033 tecmint  /usr/bin/dbus-launch --exit        0      328      360     21603468 tecmint  /bin/dbus-daemon --config-f        0      344      515     32843122 tecmint  /usr/lib/gvfs/gvfsd                0      656      801     55523471 tecmint  /usr/lib/at-spi2-core/at-sp        0      708      864     59923396 tecmint  /usr/lib/gvfs/gvfs-mtp-volu        0      804      914     62043208 tecmint  /usr/lib/x86_64-linux-gnu/i        0      892     1012     61883380 tecmint  /usr/lib/gvfs/gvfs-afc-volu        0      820     1024     63963034 tecmint  //bin/dbus-daemon --fork --        0      920     1081     30403365 tecmint  /usr/lib/gvfs/gvfs-gphoto2-        0      972     1099     60523228 tecmint  /usr/lib/gvfs/gvfsd-trash -        0      980     1153     66483107 tecmint  /usr/lib/dconf/dconf-servic        0     1212     1283     53766399 tecmint  /opt/google/chrome/chrome -        0      144     1409    107323478 tecmint  /usr/lib/x86_64-linux-gnu/g        0     1724     1820     63207365 tecmint  /usr/lib/gvfs/gvfsd-http --        0     1352     1884     87046937 tecmint  /opt/libreoffice5.0/program        0     1140     2328     50403194 tecmint  /usr/lib/x86_64-linux-gnu/p        0     1956     2405    142286373 tecmint  /opt/google/chrome/nacl_hel        0     2324     2541     89083313 tecmint  /usr/lib/gvfs/gvfs-udisks2-        0     2460     2754     87363464 tecmint  /usr/lib/at-spi2-core/at-sp        0     2684     2823     79205771 tecmint  ssh -p 4521 tecmnt765@212.7        0     2544     2864     65405759 tecmint  /bin/bash                          0     2416     2923     56403541 tecmint  /usr/bin/python /usr/bin/mi        0     2584     3008     72487657 tecmint  bash                               0     2516     3055     60283127 tecmint  /usr/lib/gvfs/gvfsd-fuse /r        0     3024     3126     80323205 tecmint  mate-screensaver                   0     2520     3331    180723171 tecmint  /usr/lib/mate-panel/notific        0     2860     3495    171403030 tecmint  x-session-manager                  0     4400     4879    175003197 tecmint  mate-volume-control-applet         0     3860     5226    23736
...
查看系统占用内存的情况
$ sudo smem -wArea                           Used      Cache   Noncache
firmware/hardware                 0          0          0
kernel image                      0          0          0
kernel dynamic memory       1425320    1291412     133908
userspace memory            2215368     451608    1763760
free memory                 4424936    4424936          0
每一个用户的内存使用情况
$ sudo smem -u
User     Count     Swap      USS      PSS      RSS
rtkit        1        0      300      326     2548
kernoops     1        0      352      385     2684
avahi        2        0      408      851     4740
postfix      2        0      648     1140     5692
messagebus     1        0     1012     1173     3320
syslog       1        0     1396     1419     3232
www-data     2        0     5100     6572    13580
mpd          1        0     7416     8302    12896
nobody       2        0     4024    11305    24728
root        39        0   323876   353418   496520
tecmint     64        0  1652888  1815699  2763112
按照映射显示内存使用情况
$ sudo smem -mMap                                       PIDs   AVGPSS      PSS
/dev/fb0                                     1        0        0
/home/tecmint/.cache/fontconfig/7ef2298f    18        0        0
/home/tecmint/.cache/fontconfig/c57959a1    18        0        0
/home/tecmint/.local/share/mime/mime.cac    15        0        0
/opt/google/chrome/chrome_material_100_p     9        0        0
/opt/google/chrome/chrome_material_200_p     9        0        0
/usr/lib/x86_64-linux-gnu/gconv/gconv-mo    41        0        0
/usr/share/icons/Mint-X-Teal/icon-theme.    15        0        0
/var/cache/fontconfig/0c9eb80ebd1c36541e    20        0        0
/var/cache/fontconfig/0d8c3b2ac0904cb8a5    20        0        0
/var/cache/fontconfig/1ac9eb803944fde146    20        0        0
/var/cache/fontconfig/3830d5c3ddfd5cd38a    20        0        0
/var/cache/fontconfig/385c0604a188198f04    20        0        0
/var/cache/fontconfig/4794a0821666d79190    20        0        0
/var/cache/fontconfig/56cf4f4769d0f4abc8    20        0        0
/var/cache/fontconfig/767a8244fc0220cfb5    20        0        0
/var/cache/fontconfig/8801497958630a81b7    20        0        0
/var/cache/fontconfig/99e8ed0e538f840c56    20        0        0
/var/cache/fontconfig/b9d506c9ac06c20b43    20        0        0
/var/cache/fontconfig/c05880de57d1f5e948    20        0        0
/var/cache/fontconfig/dc05db6664285cc2f1    20        0        0
/var/cache/fontconfig/e13b20fdb08344e0e6    20        0        0
/var/cache/fontconfig/e7071f4a29fa870f43    20        0        0
....
筛选 smem 的输出
筛选出用户名的信息

用户名筛选输出的信息,-u 或者是 --userfilter="regex" 选项

$ sudo smem -uUser     Count     Swap      USS      PSS      RSS
rtkit        1        0      300      326     2548
kernoops     1        0      352      385     2684
avahi        2        0      408      851     4740
postfix      2        0      648     1140     5692
messagebus   1        0     1012     1173     3320
syslog       1        0     1400     1423     3236
www-data     2        0     5100     6572    13580
mpd          1        0     7416     8302    12896
nobody       2        0     4024    11305    24728
root        39        0   323804   353374   496552
tecmint     64        0  1708900  1871766  2819212
筛选出进程的信息

进程名称筛选输出信息,使用-P 或者是--processfilter="regex"选项

$ sudo smem --processfilter="firefox"PID  User     Command                         Swap      USS      PSS      RSS
9212 root     sudo smem --processfilter=f        0     1172     1434     4856
9213 root     /usr/bin/python /usr/bin/sm        0     7368     7793    11984
4424 tecmint  /usr/lib/firefox/firefox           0   931732   937590   961504
-c 或者是 --columns 选项设置格式

使用 -c 或者是 --columns 选项,就像下面的命令这样:

$ sudo smem -c "name user pss rss"Name                     User          PSS      RSS
cat                      tecmint       145     1784
cat                      tecmint       147     1676
ck-launch-sessi          tecmint       165     1780
gnome-pty-helpe          tecmint       178     1832
gnome-pty-helpe          tecmint       179     1916
getty                    root          184     2052
getty                    root          187     2060
getty                    root          187     2060
getty                    root          188     2124
getty                    root          196     2064
getty                    root          196     2136
sh                       tecmint       224     1540
acpid                    root          236     1604
syndaemon                tecmint       296     2560
rtkit-daemon             rtkit         326     2548
cron                     root          333     2344
avahi-daemon             avahi         334     1632
irqbalance               root          343     2096
upstart-socket-          root          351     1820
dbus-launch              tecmint       360     2160
upstart-file-br          root          371     1776
xdm                      root          378     2368
kerneloops               kernoops      386     2684
upstart-udev-br          root          427     2132
ssh-agent                tecmint       485      992
...
以百分比的形式报告内存使用情况-p
$ sudo smem -pPID User     Command                         Swap      USS      PSS      RSS6367 tecmint  cat                            0.00%    0.00%    0.00%    0.02%6368 tecmint  cat                            0.00%    0.00%    0.00%    0.02%9307 tecmint  sh -c { sudo /usr/lib/linux    0.00%    0.00%    0.00%    0.02%2864 tecmint  /usr/bin/ck-launch-session     0.00%    0.00%    0.00%    0.02%3544 tecmint  sh -c /usr/lib/linuxmint/mi    0.00%    0.00%    0.00%    0.02%5758 tecmint  gnome-pty-helper               0.00%    0.00%    0.00%    0.02%7656 tecmint  gnome-pty-helper               0.00%    0.00%    0.00%    0.02%1441 root     /sbin/getty -8 38400 tty2      0.00%    0.00%    0.00%    0.03%1434 root     /sbin/getty -8 38400 tty5      0.00%    0.00%    0.00%    0.03%1444 root     /sbin/getty -8 38400 tty3      0.00%    0.00%    0.00%    0.03%1432 root     /sbin/getty -8 38400 tty4      0.00%    0.00%    0.00%    0.03%1452 root     /sbin/getty -8 38400 tty6      0.00%    0.00%    0.00%    0.03%2619 root     /sbin/getty -8 38400 tty1      0.00%    0.00%    0.00%    0.03%1504 root     acpid -c /etc/acpi/events -    0.00%    0.00%    0.00%    0.02%3311 tecmint  syndaemon -i 0.5 -K -R         0.00%    0.00%    0.00%    0.03%3143 rtkit    /usr/lib/rtkit/rtkit-daemon    0.00%    0.00%    0.00%    0.03%1588 root     cron                           0.00%    0.00%    0.00%    0.03%1589 avahi    avahi-daemon: chroot helpe     0.00%    0.00%    0.00%    0.02%1523 root     /usr/sbin/irqbalance           0.00%    0.00%    0.00%    0.03%585 root     upstart-socket-bridge --dae    0.00%    0.00%    0.00%    0.02%3033 tecmint  /usr/bin/dbus-launch --exit    0.00%    0.00%    0.00%    0.03%
....
最后一行汇总信息
$ sudo smem -tPID User     Command                         Swap      USS      PSS      RSS6367 tecmint  cat                                0      100      139     17846368 tecmint  cat                                0      100      141     16769307 tecmint  sh -c { sudo /usr/lib/linux        0       96      158     15082864 tecmint  /usr/bin/ck-launch-session         0      144      163     17803544 tecmint  sh -c /usr/lib/linuxmint/mi        0      108      170     15405758 tecmint  gnome-pty-helper                   0      156      176     19167656 tecmint  gnome-pty-helper                   0      156      176     18321441 root     /sbin/getty -8 38400 tty2          0      152      181     20521434 root     /sbin/getty -8 38400 tty5          0      156      184     20601444 root     /sbin/getty -8 38400 tty3          0      156      184     20601432 root     /sbin/getty -8 38400 tty4          0      156      185     21241452 root     /sbin/getty -8 38400 tty6          0      164      193     20642619 root     /sbin/getty -8 38400 tty1          0      164      193     21361504 root     acpid -c /etc/acpi/events -        0      220      232     16043311 tecmint  syndaemon -i 0.5 -K -R             0      260      298     25643143 rtkit    /usr/lib/rtkit/rtkit-daemon        0      300      324     25481588 root     cron                               0      292      326     23441589 avahi    avahi-daemon: chroot helpe         0      124      332     16321523 root     /usr/sbin/irqbalance               0      316      340     2096585 root     upstart-socket-bridge --dae        0      328      349     18203033 tecmint  /usr/bin/dbus-launch --exit        0      328      359     21601346 root     upstart-file-bridge --daemo        0      348      370     17762607 root     /usr/bin/xdm                       0      188      375     23681635 kernoops /usr/sbin/kerneloops               0      352      384     2684344 root     upstart-udev-bridge --daemo        0      400      426     2132
.....
-------------------------------------------------------------------------------134 11                                          0  2171428  2376266  3587972

简要以图形的形式报告内存的使用情况

条形图

生成一张进程的 PSS 和 RSS 值的条状图,纵坐标为每一个进程的 PSS 和 RSS 值,横坐标为 root 用户的所有进程(的 ID):

$ sudo smem --userfilter="root" --bar pid -c"pss rss"

饼形图

也可以生成进程及其 PSS 和 RSS 占用量的饼状图。以下的命令将会输出一张 root 用户的所有进程的饼状图。

--pie name 意思为以各个进程名字为标签,-s选项用来以 PSS 的值排序。

$ sudo smem --userfilter="root" --pie name -s pss

关于 smem 的介绍到此为止,不过想要更好的了解它,可以通过 man 手册,-h等方式获得更多的选项,然后一一实践。有什么想法或者疑惑,都可以跟帖评价。

本文转载地址:https://www.linuxprobe.com/smem-linux-use.html

smem – Linux 内存监视软件相关推荐

  1. Conky Linux桌面环境的系统监视软件

    0 简介 Conky 是一个应用于桌面环境的系统监视软件,可以在桌面上监控系统运行状态.网络状态等一系列参数 https://github.com/brndnmtthws/conky/ 详细配置文档: ...

  2. linux 查看 内存 占用,Linux终端:用smem查看内存占用情况

    无论是作为系统管理员,还是作为使用桌面版Linux的简单用户,你都会注意到,某个进程在耗用你系统的所有内存. 首先要明白Linux是如何管理内存的:我多次接到用户的反映,说运行了free命令,就是无法 ...

  3. 《嵌入式Linux与物联网软件开发——C语言内核深度解析》一第1章 C语言与内存1.1 引言...

    本节书摘来自异步社区<嵌入式Linux与物联网软件开发--C语言内核深度解析>一书中的第1章,第1.1节,作者朱有鹏 , 张先凤,更多章节内容可以访问云栖社区"华章计算机&quo ...

  4. linux 查看内存消耗情况,Linux终端:用smem查看内存占用情况

    无论是作为系统管理员,还是作为使用桌面版Linux的简单用户,你都会注意到,某个进程在耗用你系统的所有内存. 首先要明白Linux是如何管理内存的:我多次接到用户的反映,说运行了free命令,就是无法 ...

  5. Linux内存memtest,详细讲解 Linux极品内存检测软件 Memtest86

    Memtest86是一款免费的内存测试软件,测试准确度比较高,内存的隐性问题也能检查出来!大家可以到http://www.memtest86.com/页面下载它的最新3.0版本. Memtest86是 ...

  6. linux的fq软件github,曾经霸榜 GitHub:漂亮开源的 Linux 资源监视工具

    原标题:曾经霸榜 GitHub:漂亮开源的 Linux 资源监视工具 来自:Linux迷 https://www.linuxmi.com/bashtop-linux.html Bashtop是Linu ...

  7. linux 内存虚拟盘,Linux_内存虚拟盘软件XMSDSK的使用教程,随着时代的发展,电脑的内存 - phpStudy...

    内存虚拟盘软件XMSDSK的使用教程 随着时代的发展,电脑的内存越来越大,从原来的1M.2M.4M等发展到现在的128M.256M.512M,甚至更大.因此,合理分配和使用内存是非常重要的,以避免不必 ...

  8. linux清理内存垃圾 强力,linux强制删除软件强力清除残留配置

    Linux概述在系统使用过程中, 不可避免的要安装各种软件, 当软件不用时, 需要卸载释放空间, Linux 安装卸载软件不像Win那样有很完善的软件管理机制, 就算Win自己的不够给力, 也有大量第 ...

  9. Linux系统下***软件大荟萃

    Linux系统下***软件大荟萃(zt) Linux系统下***软件大荟萃 现在,大量的网络服务器开始使用Linux操作系统,Linux服务器的安全性也开始受到关注.对Linux服务器***的定义是: ...

最新文章

  1. Windows10下Python3做OpenGL的编程
  2. Elastic Search 上市了,Slack上市了,我也要写个软件,走上人生巅峰
  3. java web 图书管理系统_图书管理系统,源代码 Java初级小项目
  4. hdu 3819动态规划
  5. 认识软件性能测试10大误区
  6. python判断ip能否ping通_使用Python测试Ping主机IP和某端口是否开放的实例
  7. SpringBoot之Bean之条件注入@ConditionalOnExpression
  8. jquery中的each不能结束外层的function
  9. kettle将文件路径定义为_Kettle变量和自己定义java代码的实例应用
  10. Python 数据科学手册
  11. C++ 验证DH算法
  12. 2.7 SLD参考标准与GeoServer扩展
  13. iOS 音乐播放器(二)
  14. 菜单栏、工具栏、状态栏
  15. C++学习笔记:实现向量类的加减赋值运算,重载运算符
  16. 并查集 --算法竞赛专题解析(3)
  17. go语言操作mongoDB之mgo
  18. 生活记录:记录2020暑假前半部分时光
  19. 87: 企业监控系统部署 、 搭建Harbor私有仓库 、 总结和答疑
  20. 汽车之家搜索算法工程师招聘

热门文章

  1. Boost: 对uncaught_exceptions函数的测试
  2. boost::contract模块实现虚拟可选结果的测试程序
  3. Boost:是否支持sse2指令的测试程序
  4. Boost:assume aligned假设对齐的测试程序
  5. DCMTK:定义信号灯,互斥锁和读/写锁的类
  6. DCMTK:创建,写入和读取二进制细分对象
  7. VTK:可视化之MovableAxes
  8. VTK:Shaders之SphereMap
  9. QT的QSqlDatabase类的使用
  10. c++ 类和类的定义