Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and use Smem in Linux

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to install and use Smem in Linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Smem is a memory usage reporting tool under the command line, which can provide users with a variety of reports on memory usage under Linux systems. Unlike existing tools, seme can report PSS (physical memory actually used (PSS), thus measuring the amount of memory occupied by virtual memory system libraries and applications.

Install the Smem-Linux tool

Installation conditions:

Modern kernel (version number higher than 2.6.27) newer Python versions (2.4 and later) optional matplotlib library for chart generation

For most of today's Linux distributions, both the kernel version and the Python version meet your needs, so you only need to install the matplotlib library for generating good diagrams.

RHEL, CentOS and Fedora

First enable the EPEL (Extra Packages for Enterprise Linux) software source, and then follow these steps:

# yum install smem python-matplotlib python-tk

Debian and Ubuntu

$sudo apt-get install smem

Linux Mint

$sudo apt-get install smem python-matplotlib python-tk

Arch Linux

Use this https://www.archlinux.org/packages/community/i686/smem/" 's AUR repository.

The use of Smem-Linux

Memory usage

$sudo smem PID User Command Swap USS PSS RSS6367 tecmint cat 0 100 145 17846368 tecmint cat 0 100 147 16762864 tecmint / usr/bin/ck-launch-session 0144 165 17807656 tecmint gnome-pty-helper 0156 178 18325758 tecmint gnome-pty-helper 0156 179 19161441 root / sbin/getty-8 38400 tty2 0152 184 20521434 root / sbin/getty-8 38400 tty5 0156 187 20601444 root / sbin/getty-8 38400 tty3 0156 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 0212 224 15401504 root acpid-c / etc/acpi/events-0220 236 16043311 tecmint syndaemon-I 0.5-K-R 0 252 292 25563143 rtkit/ usr/lib/rtkit/rtkit-daemon 0300 326 25481588 root cron 0292 333 23441589 avahi avahi-daemon: chroot helpe 0124 334 16321523 root / usr/sbin/irqbalance 0316343 2096 2096 root upstart-socket-bridge-- dae 0328351 18203033 tecmint / usr/bin/dbus-launch-- exit 0328360 21601346 root upstart-file-bridge-- daemo 0348371 17762607 root / usr/bin/xdm 0188 378 23681635 kernoops / usr / sbin/kerneloops 0352 386 2684 344 root upstart-udev-bridge-- daemo 0400 427 21322960 tecmint / usr/bin/ssh-agent / usr/bin 0480 485 9923468 tecmint / bin/dbus-daemon-- config-f 0344,515 32841559 avahi avahi-daemon: running [tecm 0284,517 31087289 postfix pickup-l-t unix-u-c 0 288 534 28082135 root / usr/lib/postfix/master 0352 576 28722436 postfix qmgr-l-t unix-u 0360 606 28841521 root / lib/systemd/systemd-logind 0600 650 32762222 nobody / usr/sbin/dnsmasq-- no-reso 0 604 669 3288....

Check the memory consumption of user processes

The average user runs smem, which shows the occupancy of the process by that user, and sorts it in ascending order of PSS value.

$smem PID User Command Swap USS PSS RSS6367 tecmint cat 0 100 145 17846368 tecmint cat 0 100 147 16762864 tecmint / usr/bin/ck-launch-session 0144 166 17803544 tecmint sh-c / usr/lib/linuxmint/ Mi 0212 224 15403311 tecmint syndaemon-I 0.5-K-R 0252 292 25563033 tecmint / usr/bin/dbus-launch-- exit 0328 360 21603468 tecmint / bin/dbus-daemon-- config-f 0344,515 32843122 tecmint / usr/lib/gvfs/gvfsd 0656 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-- 0920 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 012121283 53766399 tecmint / opt/google/chrome/chrome-0144 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 01140 2328 50403194 tecmint / usr/lib/x86_64-linux-gnu/p 01956 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 02684 2823 79205771 tecmint ssh-p 4521 tecmnt765@212.7 02544 2864 65405759 tecmint / bin/bash 02416 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...

Check the memory consumption of the system

$sudo smem-wArea Used Cache Noncachefirmware/hardware 0 0 0kernel image 0 0 0kernel dynamic memory 1425320 1291412 133908userspace memory 2215368 451608 1763760free memory 4424936 4424936

Memory usage of each user

$sudo smem-uUser Count Swap USS PSS RSSrtkit 10 300 326 2548kernoops 10 352 385 2684avahi 20 408 851 4740postfix 20 648 1140 5692messagebus 10 1012 1173 3320syslog 10 1396 1419 3232 www- Data 20 5100 6572 13580mpd 10 7416 8302 12896nobody 20 4024 11305 24728root 39 0 323876 353418 496520tecmint 64 0 1652888 1815699 2763112

Display memory usage by mapping

$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 00 / opt/google/chrome/chrome_material_100_p 9 00 / opt/google/chrome/chrome_material_200_p 9 00 / usr/lib/x86_64-linux-gnu/gconv/gconv-mo 41 00 / 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....

Filter the output of smem

Filter out the information of the user name

User name filter output information,-u or-userfilter= "regex" option

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

Filter out the information of the process

Process name filter output information, using-P or-processfilter= "regex" option

$sudo smem-- processfilter= "firefox" PID User Command Swap USS PSS RSS9212 root sudo smem-- processfilter=f 0 1172 1434 48569213 root / usr/bin/python / usr/bin/sm 0 7368 7793 119844424 tecmint / usr/lib/firefox/firefox 0931732 937590 961504

-c or-columns option to format

Use the-c or-columns option, like the following command:

Sudo smem-c "name user pss rss" Name User PSS RSScat tecmint 1451784cat tecmint 1471651780gnome-pty-helpe tecmint 1781832gnome-pty-helpe tecmint 1791916getty Root 184 2052getty root 187 2060getty root 187 2060getty root 188 2124getty root 196 2064getty root 196 2136sh tecmint 224 1540acpid root 236 1604syndaemon tecmint 296 2560rtkit-daemon rtkit 326 2548cron root 333 2344avahi-daemon avahi 334 1632irqbalance root 343 2096upstartMusco root 351 1820dbus-launch tecmint 360 2160upstart-file-br root 371 1776xdm root 378 2368kerneloops kernoops 386 2684upstart-udev-br root 427 2132ssh-agent tecmint 485 992...

Report memory usage as a percentage-p

$sudo smem-pPID User Command Swap USS PSS RSS6367 tecmint cat 0.00% 0.002% 6368 tecmint cat 0.00% 0.002% 0.02% 9307 tecmint sh-c {sudo / usr/lib/linux 0.002% 2864 tecmint / usr/bin/ck-launch-session 0.00% 0.002% 0.02% 3544 tecmint sh-c / usr/lib/linuxmint/mi 0.00% 0.00% 0.002% 5758 tecmint gnome-pty-helper 0.00% 0.00% 0.002% 7656 tecmint gnome-pty-helper 0.00% 0.00% 0.0241 root / sbin/getty-8 38400 tty2 0.00% 0.00% 0.0334 root / sbin/getty-8 38400 tty5 0.00% 0.00% 0.0344 root / sbin/ Getty-8 38400 tty3 0.00% 0.00% 0.0332 root / sbin/getty-8 38400 tty4 0.00% 0.00% 0.0352 root / sbin/getty-8 38400 tty6 0.00% 0.003% 2619 root / sbin/getty-8 38400 tty1 0.00% % 0.002% 0.0304 root acpid-c / etc/acpi/events-0.00% 0.00% 0.002% 3311 tecmint syndaemon-I 0.5-K-R 0.00% 0.00% 0.003% 3143 rtkit/ usr/lib/rtkit/rtkit-daemon 0.00% 0.00% 0.00% 0.0388 root cron 0.003% 0.0000% 0.0389 avahi avahi-daemon: chroot helpe 0.003% 0.0223 root / usr/sbin/irqbalance 0.000% 0.003% 585 root upstart-socket-bridge-- dae 0.002% 0.02% 3033 tecmint / usr/bin/dbus-launch-- exit 0.00% 0.00% 0.003%....

Last line summary information

$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 096 158 15082864 tecmint / usr/bin/ck- Launch-session 0144163 17803544 tecmint sh-c / usr/lib/linuxmint/mi 0108 170 15405758 tecmint gnome-pty-helper 0156 176 19167656 tecmint gnome-pty-helper 0156 176 18321441 root / sbin/getty-8 38400 tty2 0152 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-0220 232 16043311 tecmint syndaemon-I 0 260 298 25643143 rtkit/ usr/lib/rtkit/rtkit-daemon 0300 324 25481588 root cron 0292 326 23441589 avahi avahi-daemon: chroot helpe 0 124 332 16321523 root / usr/sbin/irqbalance 0316 340 2096 585 root upstart-socket-bridge-- dae 0328349 18203033 tecmint / usr/bin/dbus-launch-- exit 0328359 21601346 root upstart-file-bridge-- daemo 0348370 17762607 root / usr/ Bin/xdm 0188 375 23681635 kernoops / usr/sbin/kerneloops 0352 384 2684 344 root upstart-udev-bridge-- daemo 0400 426 2132. -- 13411 0 2171428 2376266 3587972

Briefly report memory usage in the form of graphics

Bar chart

Generate a bar chart of the PSS and RSS values of a process, with the ordinate as the PSS and RSS values of each process, and the Abscissa as the ID of all processes of the root user:

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

Pie chart

You can also generate a pie chart of the process and its PSS and RSS usage. The following command will output a pie chart of all the processes of the root user.

-pie name means labeled by the name of each process, and the-s option is used to sort by the value of PSS.

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

Thank you for reading this article carefully. I hope the article "how to install and use Smem in Linux" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 276

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report