ps_mem is a simple Python script that allows you to get a core memory usage accurately for the programs in Linux.
There are many applications on Linux to view memory usage such as free command, VMstat command, Smem command and Top command.
But this application is slightly different when compared to the others because it accurately displays the core memory usage.It calculates the amount of private and shared memory against to a program and gives the total amount of RAM used.
This will surely help everyone to understand which program consumes more RAM.
You can install the ps_mem application in a number of ways, either through the Distribution Package Manager or through the PIP Package Manager or direct method (by running the ps_mem.py Python script).
Please note, It needs a root privilege.
Method-1: How to install the ps_mem application on Linux using Distribution Package Manager
The RHEL based system has the ps_mem utility in the default repository, so it can be easily installed through the package manager.
For RHEL/CentOS, use yum Package Manager to install ps_mem package.
$ sudo yum install ps_mem
For Fedora/RHEL 8/CentOS 8 systems, use dnf Package Manager to install ps_mem package.
$ sudo dnf install ps_mem
For Arch Linux, use pacman Package Manager to install ps_mem package.
$ sudo pacman -S ps_mem
Method-2: How to install the ps_mem package on Linux using the PIP Package Manager
PIP is a recommended tool for installing Python packages on Linux. Use the pip command instead of the distribution package manager to get the latest build of ps_mem package.
Make sure you have the pip package installed on your system to use the pip Package Manager. If this is not already installed, install the python-pip
package using the distribution Package Manager.
For Debian based systems.
$ sudo apt-get install python-pip
For RHEL/CentOS based systems.
$ sudo yum install python-pip
For Fedora
$ sudo dnf install python-pip
For openSUSE
$ sudo zypper install python-pip
For Arch Linux based systems
$ sudo pacman -S python-pip
Finally use the pip Package Manager to install the ps_mem package on Linux.
$ sudo pip install ps_mem
Method-3: How to use ps_mem.py Python script directly on Linux
Alternatively, you can run the ps_mem.py
script directly by downloading the file from the developer github page.
$ git clone https://github.com/pixelb/ps_mem.git && cd ps_mem $ sudo python ps_mem.py
How to use ps_mem command in Linux ?
Run the ps_mem
command without any option to get the core memory usage accurately for per program.
$ sudo ps_mem Private + Shared = RAM used Program 168.0 KiB + 29.0 KiB = 197.0 KiB xf86-video-intel-backlight-helper (2) 188.0 KiB + 66.0 KiB = 254.0 KiB cat (2) 308.0 KiB + 37.5 KiB = 345.5 KiB lvmetad 380.0 KiB + 32.5 KiB = 412.5 KiB rtkit-daemon 392.0 KiB + 26.5 KiB = 418.5 KiB crond 832.0 KiB + 112.0 KiB = 944.0 KiB gnome-session-ctl (2) 968.0 KiB + 55.5 KiB = 1.0 MiB gvfs-mtp-volume-monitor 1.1 MiB + 40.5 KiB = 1.1 MiB dconf-service 1.0 MiB + 102.5 KiB = 1.1 MiB gvfs-goa-volume-monitor 1.0 MiB + 178.5 KiB = 1.2 MiB gvfsd 1.1 MiB + 139.5 KiB = 1.3 MiB fprintd 1.2 MiB + 49.5 KiB = 1.3 MiB gvfsd-fuse 1.2 MiB + 208.0 KiB = 1.4 MiB xdg-permission-store (2) 1.2 MiB + 173.5 KiB = 1.4 MiB gsd-disk-utility-notify . . 19.0 MiB + 1.9 MiB = 20.9 MiB lollypop-sp 20.3 MiB + 2.0 MiB = 22.3 MiB blueman-applet 18.4 MiB + 3.9 MiB = 22.4 MiB evolution-calendar-factory 20.1 MiB + 2.4 MiB = 22.5 MiB blueman-tray 15.3 MiB + 7.7 MiB = 23.0 MiB systemd-journald 22.3 MiB + 746.0 KiB = 23.1 MiB gsd-keyboard (2) 22.4 MiB + 793.0 KiB = 23.2 MiB gsd-wacom (2) 23.2 MiB + 930.0 KiB = 24.1 MiB gsd-xsettings (2) 15.3 MiB + 8.9 MiB = 24.3 MiB evolution-alarm-notify 23.5 MiB + 1.6 MiB = 25.1 MiB gsd-color (2) 23.9 MiB + 1.2 MiB = 25.1 MiB gsd-media-keys (2) 24.2 MiB + 1.3 MiB = 25.5 MiB gsd-power (2) 26.3 MiB + 2.3 MiB = 28.6 MiB c 28.6 MiB + 2.1 MiB = 30.7 MiB chrome-gnome-sh (2) 48.8 MiB + 6.7 MiB = 55.5 MiB goa-daemon 62.3 MiB + 6.4 MiB = 68.7 MiB WebExtensions 87.2 MiB + 55.7 MiB = 142.8 MiB Xorg (2) 210.6 MiB + 25.3 MiB = 235.9 MiB notepadqq-bin 368.7 MiB + 29.4 MiB = 398.1 MiB gnome-shell (2) 536.6 MiB + 137.6 MiB = 674.3 MiB firefox 886.0 MiB + 107.4 MiB = 993.5 MiB chrome (14) 2.4 GiB + 183.5 MiB = 2.5 GiB Web Content (8) --------------------------------- 5.7 GiB =================================
Add the -s
option with the ps_mem command to get the full path of the program instead of the program name.
$ sudo ps_mem -s Private + Shared = RAM used Program 168.0 KiB + 29.0 KiB = 197.0 KiB xf86-video-intel-backlight-helper intel_backlight (2) 188.0 KiB + 66.0 KiB = 254.0 KiB cat (2) 308.0 KiB + 37.5 KiB = 345.5 KiB /usr/bin/lvmetad -f 380.0 KiB + 32.5 KiB = 412.5 KiB /usr/lib/rtkit-daemon 392.0 KiB + 26.5 KiB = 418.5 KiB /usr/bin/crond -n 448.0 KiB + 101.5 KiB = 549.5 KiB less 648.0 KiB + 91.5 KiB = 739.5 KiB /usr/lib/gdm-x-session gnome-session --autostart /usr/share/gdm/greeter/autostart 648.0 KiB + 91.5 KiB = 739.5 KiB /usr/lib/gdm-x-session --run-script /usr/bin/gnome-session . . 179.7 MiB + 13.2 MiB = 192.9 MiB /usr/lib/firefox/firefox -contentproc -childID 1 -isForBrowser -prefsLen 1 -prefMapSize 218689 -parentBuildID 20200108131950 -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 1701 true tab 210.6 MiB + 25.3 MiB = 235.9 MiB /usr/bin/../lib/notepadqq/notepadqq-bin 234.9 MiB + 12.3 MiB = 247.2 MiB /usr/lib/firefox/firefox -contentproc -childID 10 -isForBrowser -prefsLen 8049 -prefMapSize 218689 -parentBuildID 20200108131950 -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 1701 true tab 251.2 MiB + 13.9 MiB = 265.1 MiB /usr/lib/firefox/firefox -contentproc -childID 7 -isForBrowser -prefsLen 8049 -prefMapSize 218689 -parentBuildID 20200108131950 -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 1701 true tab 261.6 MiB + 11.5 MiB = 273.1 MiB /usr/lib/firefox/firefox -contentproc -childID 16 -isForBrowser -prefsLen 8049 -prefMapSize 218689 -parentBuildID 20200108131950 -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 1701 true tab 273.0 MiB + 9.4 MiB = 282.5 MiB /opt/google/chrome/chrome --type=renderer --field-trial-handle=14830905625952148903,693558806252868729,131072 --service-pipe-token=10778886472037153786 --lang=en-GB --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --num-raster-threads=4 --enable-main-frame-before-activation --service-request-channel-token=10778886472037153786 --renderer-client-id=6 --no-v8-untrusted-code-mitigations --shared-files=v8_context_snapshot_data:100,v8_natives_data:101 276.8 MiB + 26.8 MiB = 303.6 MiB /usr/lib/firefox/firefox -contentproc -childID 15 -isForBrowser -prefsLen 8049 -prefMapSize 218689 -parentBuildID 20200108131950 -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 1701 true tab 334.2 MiB + 12.4 MiB = 346.6 MiB /usr/lib/firefox/firefox -contentproc -childID 11 -isForBrowser -prefsLen 8049 -prefMapSize 218689 -parentBuildID 20200108131950 -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 1701 true tab 237.1 MiB + 142.2 MiB = 379.3 MiB /usr/lib/firefox/firefox -contentproc -childID 18 -isForBrowser -prefsLen 9566 -prefMapSize 218689 -parentBuildID 20200108131950 -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 1701 true tab 368.6 MiB + 29.4 MiB = 397.9 MiB /usr/bin/gnome-shell (2) 618.8 MiB + 11.5 MiB = 630.3 MiB /usr/lib/firefox/firefox -contentproc -childID 4 -isForBrowser -prefsLen 6894 -prefMapSize 218689 -parentBuildID 20200108131950 -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 1701 true tab 543.1 MiB + 197.9 MiB = 741.0 MiB /usr/lib/firefox/firefox --new-window --------------------------------- 5.8 GiB =================================
If you want to view the memory usage of a particular program or more than one program, you can see this by adding their PIDs as follows.
$ sudo ps_mem -p 4152,2123,2898 Private + Shared = RAM used Program 129.5 MiB + 13.4 MiB = 142.9 MiB chrome 210.6 MiB + 25.3 MiB = 235.9 MiB notepadqq-bin 261.4 MiB + 115.7 MiB = 377.1 MiB Web Content --------------------------------- 755.9 MiB =================================
Use the following format to print memory consumption every “N” seconds. The following command format reports memory usage every 2 seconds.
$ sudo ps_mem w 2
To show separate memory usage entries by process rather than by program.
$ sudo ps_mem -d Private + Shared = RAM used Program[pid] 84.0 KiB + 14.5 KiB = 98.5 KiB xf86-video-intel-backlight-helper [880] 84.0 KiB + 14.5 KiB = 98.5 KiB xf86-video-intel-backlight-helper [1151] 92.0 KiB + 32.5 KiB = 124.5 KiB cat [2905] 96.0 KiB + 33.5 KiB = 129.5 KiB cat [2906] 308.0 KiB + 37.5 KiB = 345.5 KiB lvmetad [256] 380.0 KiB + 32.5 KiB = 412.5 KiB rtkit-daemon [938] 392.0 KiB + 26.5 KiB = 418.5 KiB crond [657] 416.0 KiB + 53.5 KiB = 469.5 KiB gnome-session-ctl [1202] 416.0 KiB + 57.5 KiB = 473.5 KiB gnome-session-ctl [913] 448.0 KiB + 83.5 KiB = 531.5 KiB less [18316] 428.0 KiB + 118.5 KiB = 546.5 KiB dbus-daemon [903] . . 169.2 MiB + 9.2 MiB = 178.4 MiB chrome [5111] 210.6 MiB + 25.3 MiB = 235.9 MiB notepadqq-bin [2123] 235.3 MiB + 15.4 MiB = 250.8 MiB gnome-shell [1219] 245.2 MiB + 11.6 MiB = 256.8 MiB Web Content [5034] 268.4 MiB + 10.1 MiB = 278.6 MiB Web Content [4939] 275.1 MiB + 9.4 MiB = 284.5 MiB chrome [3076] 297.2 MiB + 13.2 MiB = 310.3 MiB Web Content [1776] 320.5 MiB + 12.3 MiB = 332.8 MiB Web Content [4152] 339.4 MiB + 12.4 MiB = 351.8 MiB Web Content [4241] 380.9 MiB + 70.9 MiB = 451.8 MiB Web Content [14457] 455.0 MiB + 13.9 MiB = 468.9 MiB Web Content [3827] 615.3 MiB + 11.5 MiB = 626.9 MiB Web Content [1955] 559.9 MiB + 109.9 MiB = 669.9 MiB firefox [1701] --------------------------------- 6.1 GiB =================================
Show swap information of each item (and Shared swap if the kernel supports SwapPss).
$ sudo ps_mem -S Private + Shared = RAM used Swap used Program 168.0 KiB + 29.0 KiB = 197.0 KiB 0.0 KiB xf86-video-intel-backlight-helper (2) 188.0 KiB + 66.0 KiB = 254.0 KiB 0.0 KiB cat (2) 308.0 KiB + 37.5 KiB = 345.5 KiB 0.0 KiB lvmetad 380.0 KiB + 32.5 KiB = 412.5 KiB 0.0 KiB rtkit-daemon 392.0 KiB + 26.5 KiB = 418.5 KiB 0.0 KiB crond 448.0 KiB + 83.5 KiB = 531.5 KiB 0.0 KiB less 832.0 KiB + 111.0 KiB = 943.0 KiB 0.0 KiB gnome-session-ctl (2) 968.0 KiB + 55.5 KiB = 1.0 MiB 0.0 KiB gvfs-mtp-volume-monitor 1.1 MiB + 40.5 KiB = 1.1 MiB 0.0 KiB dconf-service 1.0 MiB + 102.5 KiB = 1.1 MiB 0.0 KiB gvfs-goa-volume-monitor 1.0 MiB + 178.5 KiB = 1.2 MiB 0.0 KiB gvfsd 1.2 MiB + 49.5 KiB = 1.3 MiB 0.0 KiB gvfsd-fuse . . 24.2 MiB + 1.3 MiB = 25.5 MiB 0.0 KiB gsd-power (2) 26.3 MiB + 2.3 MiB = 28.6 MiB 0.0 KiB c 28.6 MiB + 2.1 MiB = 30.7 MiB 0.0 KiB chrome-gnome-sh (2) 48.8 MiB + 6.7 MiB = 55.5 MiB 0.0 KiB goa-daemon 65.1 MiB + 6.4 MiB = 71.5 MiB 0.0 KiB WebExtensions 87.4 MiB + 55.7 MiB = 143.1 MiB 0.0 KiB Xorg (2) 210.6 MiB + 25.3 MiB = 235.9 MiB 0.0 KiB notepadqq-bin 369.0 MiB + 29.4 MiB = 398.3 MiB 0.0 KiB gnome-shell (2) 559.9 MiB + 109.9 MiB = 669.9 MiB 0.0 KiB firefox 900.7 MiB + 107.6 MiB = 1.0 GiB 0.0 KiB chrome (14) 2.9 GiB + 155.9 MiB = 3.0 GiB 0.0 KiB Web Content (8) --------------------------------------------- 6.1 GiB 0.0 KiB =============================================
To display only the total number of bytes for the selected processes
$ sudo ps_mem -t 6644320768