There are several ways to see how much RAM is used in a Linux system with tools like free, vmstat, top, etc…, but today I’ve come across ps_mem which displays the RAM used for each program in a neat way.
The post on lintut.com explains how to install it on Centos / Fedora:
1 |
yum install ps_mem -y |
As a Ubuntu user, I immediately tried apt-get install ps_mem, but there isn’t such package. After running apt-file search, I found it in w3af-console package:
1 2 3 |
sudo apt-get install w3af-console sudo chmod +x /usr/share/w3af/core/controllers/profiling/ps_mem.py sudo ln -s /usr/share/w3af/core/controllers/profiling/ps_mem.py /usr/sbin/ps_mem |
Another way to install the script is to simply get it from Github.
Running the command without options will list of programs with RAM usage from the smallest to the largest:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
sudo ps_mem Private + Shared = RAM used Program 4.0 KiB + 33.0 KiB = 37.0 KiB inetutils-inetd 4.0 KiB + 35.0 KiB = 39.0 KiB rpc.idmapd 4.0 KiB + 39.5 KiB = 43.5 KiB rpc.mountd 4.0 KiB + 48.5 KiB = 52.5 KiB rpc.statd 8.0 KiB + 62.0 KiB = 70.0 KiB atieventsd 44.0 KiB + 46.5 KiB = 90.5 KiB rtkit-daemon 96.0 KiB + 18.5 KiB = 114.5 KiB cat ............ 150.5 MiB + 5.1 MiB = 155.6 MiB gimp-2.8 186.5 MiB + 9.5 MiB = 196.0 MiB plugin-container 270.8 MiB + 12.1 MiB = 282.9 MiB compiz 348.5 MiB + 19.0 MiB = 367.5 MiB nautilus 409.3 MiB + 3.4 MiB = 412.7 MiB thunderbird 393.8 MiB + 28.0 MiB = 421.8 MiB Xorg 2.1 GiB + 11.0 MiB = 2.1 GiB firefox --------------------------------- 5.0 GiB ================================= |
You can also check the full command line for the programs:
sudo ps_mem -s
Private + Shared = RAM used Program4.0 KiB + 31.5 KiB = 35.5 KiB /sbin/getty -8 38400 tty5
4.0 KiB + 32.0 KiB = 36.0 KiB /sbin/getty -8 38400 tty3
4.0 KiB + 32.0 KiB = 36.0 KiB /sbin/getty -8 38400 tty1
4.0 KiB + 32.5 KiB = 36.5 KiB /sbin/getty -8 38400 tty2
4.0 KiB + 33.0 KiB = 37.0 KiB /sbin/getty -8 38400 tty6
4.0 KiB + 33.0 KiB = 37.0 KiB /sbin/getty -8 38400 tty4
4.0 KiB + 33.0 KiB = 37.0 KiB /usr/sbin/inetutils-inetd
............
155.9 MiB + 4.3 MiB = 160.2 MiB gimp-2.8
186.3 MiB + 9.3 MiB = 195.6 MiB /usr/lib/firefox/plugin-container /usr/lib/flashplugin-installer/libflashplayer.so -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 3746 true plugin
265.0 MiB + 9.4 MiB = 274.4 MiB compiz
343.2 MiB + 2.8 MiB = 346.0 MiB /usr/lib/thunderbird/thunderbird
352.5 MiB + 28.0 MiB = 380.5 MiB /usr/bin/X -core :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
366.7 MiB + 18.6 MiB = 385.3 MiB nautilus -n
2.2 GiB + 9.3 MiB = 2.3 GiB /usr/lib/firefox/firefox
---------------------------------
4.9 GiB
=================================
If you are only interested in one or more program, add the PID list to the command line:
1 2 3 4 5 6 7 8 |
sudo ps_mem -s -p 3746,3665 Private + Shared = RAM used Program 344.0 MiB + 2.8 MiB = 346.8 MiB /usr/lib/thunderbird/thunderbird 2.2 GiB + 9.3 MiB = 2.2 GiB /usr/lib/firefox/firefox --------------------------------- 2.6 GiB ================================= |
Finally, if you want to update the memory usage values every X seconds run:
1 |
sudo ps_mem -w X |
You can also combine it with a PID list, if you only want to track one or more programs.
Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.
Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress
didn’t know this , thank for the tip
nice… it’s literally a few kb python script though so installing the package is a bit overkill (on ubuntu etc)
wget https://github.com/pixelb/ps_mem/raw/master/ps_mem.py
sudo python ps_mem.py
ps_mem reports 771.1 MiB and htop 867 MB ?! Perhaps 771 Miga Bytes = 867 Mega Bytes. 🙂 Ubuntu 10.04
great utility !
thanks
@@lex
That would be Mebi Byte but
771MiB = 808452096 Bytes = 808 MB. Still too short.
1MiB = 1024×1024 Bytes
1MB = 1000×1000 Bytes
Yeah calculating memory usage for a program is very hard. Just as hard as disk usage in BTRFS.
Virtual memory Real memory
Share memory can’t be assigned to a single process. It’s shared.
ZRAM,ZCAHCE,etc.
etc. etc.
@Falcon1
You are right, this makes sense.