top (or htop) is the most popular tool to check per-process memory usage on Linux. However, there are situations where you may want more specific information. For example, what is the total memory used by all the instances of a single process (do you use Chromium based browsers?) or how is X11 (Linux graphics susbsystem) resources used by each process? We will explore 2 unique tools in this article.

ps_mem

ps_mem is a python utility that shows you the total memory usage by all instances of the same executable. It should be run as root. The output is simple and the units are human-friendly:

$ sudo ./ps_mem.py Private + Shared = RAM used Program 100.0 KiB + 84.0 KiB = 184.0 KiB synaptic-pkexec 148.0 KiB + 52.0 KiB = 200.0 KiB cat 192.0 KiB + 38.0 KiB = 230.0 KiB atd ... 776.0 KiB + 213.5 KiB = 989.5 KiB indicator-bluetooth-service 792.0 KiB + 223.0 KiB = 1.0 MiB gvfs-mtp-volume-monitor 816.0 KiB + 199.0 KiB = 1.0 MiB menu-cached ... 24.0 MiB + 2.4 MiB = 26.4 MiB Xorg 29.2 MiB + 3.6 MiB = 32.8 MiB pcmanfm 107.4 MiB + 3.8 MiB = 111.1 MiB synaptic 450.3 MiB + 105.5 MiB = 555.8 MiB yandex_browser (12) --------------------------------- 881.5 MiB =================================

As you can see from the last entry, there are 12 instances on Yandex browser running using ~450MB of memory.

To install ps_mem on Linux:

$ git clone https://github.com/pixelb/ps_mem/ $ cd ps_mem

Syntax:

$ ps_mem.py [-h|--help] [-p PID,...] [-s|--split-args] [-t|--total] [-w N]

Check the processes that belong to current user:

$ sudo ./ps_mem.py -p $(pgrep -d, -u $USER)

Show memory usage per user:

$ for i in $(ps -e -o user= | sort | uniq); do printf '%-20s%10s

' $i $(sudo ./ps_mem.py --total -p $(pgrep -d, -u $i)); done

xrestop

xrestop is intended for debugging X11 related issues but you can use it to monitor X11 server resources used by (X11) clients. To install on Ubuntu, run:

$ sudo apt-get install xrestop

You do not need root permission to use xrestop. Simply run:

$ xrestop xrestop - Display: localhost Monitoring 22 clients. XErrors: 0 Pixmaps: 11758K total, Other: 45K total, All: 11803K total res-base Wins GCs Fnts Pxms Misc Pxm mem Other Total PID Identifier 0000000 1 0 2 0 104 6958K 4K 6962K ? 1600000 6 26 1 3 28 2433K 2K 2435K 1714 pcmanfm 1200000 15 30 0 15 20 1495K 1K 1497K 1713 panel 1400000 200 5 1 62 367 428K 14K 442K ? Openbox 0a00000 4 4 1 2 21 384K 1K 385K 1586 lxsession 1800000 6 2 1 6 64 59K 2K 61K 1742 xrestop 2600000 3 1 0 0 545 0B 12K 12K ? 1e00000 10 27 1 1 12 4B 2K 2K 20727 x-www-browser 2400000 3 1 1 0 25 0B 1K 1K 20727 New Post �~@~T WordPress.com - Yandex 0c00000 3 1 0 0 29 0B 792B 792B 1680 ibus-ui-gtk3 0800000 5 1 0 0 6 0B 288B 288B 1682 ibus-x11 1000000 1 1 0 0 1 0B 72B 72B ? ...

Can you see that it shows the X11 resource usage by the tab opened in Yandex to write this article?