Since google chrome/chromium spawn multiple processes it's harder to see how much total memory these processes use in total.
Is there an easy way to see how much total memory a series of connected processes is using?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communitySince google chrome/chromium spawn multiple processes it's harder to see how much total memory these processes use in total.
Is there an easy way to see how much total memory a series of connected processes is using?
Given that google killed chrome://memory in March 2016, I am now using smem:
# detailed output, in kB apparently
smem -t -P chrom
# just the total PSS, with automatic unit:
smem -t -k -c pss -P chrom | tail -n 1
chrom
by full path e.g. /opt/google/chrome
or /usr/lib64/chromium-browser
-P firefox
sudo smem
for that. 338.0M
. This is too low. When I run System Monitor, I can see that there are 11 chrome processes and each is taking between 70MB and 400MB of RAM. Not sure if System Monitor is reporting incorrectly or not.
Apr 5, 2017 at 15:40
chrome
instead of just chorm
because if you are running both chrome and chromium, you 'd be seeing total for both.
smem
from its own output by using something like [c]hrome
, e.g. smem -tkP '[c]hrome'
. This works by matching the c
inside the square brackets and not the brackets themselves.
Improving solution of @eddygeek:
smem -ktP chrome
Take a look on the value of column "USS", on last line
Note: you can also create an alias for this:
alias mem='smem -ktP '
And then use:
mem chrome
I'm sure that it's not the best solution, still it works for me:
#!/bin/sh
ps aux | grep "[/]opt/google/chrome/chrome" | awk '{print $5}' | awk '{sum += $1 } END { print sum }'
ps aux | grep "[/]opt/google/chrome/chrome" | awk '{print $6}' | awk '{sum += $1 } END { print sum }'
Note: change the [/]opt/google/chrome/chrome
to something appropriate for your system, e.g. if you're on Mac OS X (simply grep "chrome"
will work).
awk
commands? That is, why not just ... | awk '{sum += $6} END {print sum}'
?
ps aux | grep "/opt/google/chrome/chrome" | awk '{vsz += $5; rss += $6} END { print "vsz="vsz, "rss="rss }'
smem
per the top answer. Though FWIW, I would implement it as a script or function, since it's too complex for an alias.
Running this:
perl -e '$a="x"x1000000000;sleep(10);print"done\n"'
takes up 1.8GB RAM. So you would expect running this:
perl -e '$a="x"x1000000000;fork;fork;fork;fork;sleep(10);print"done\n"'
would take up 16 times as much. But it does not.
This is due to the Linux kernel's intelligent copy-on-write: Because the contents of '$a' does not change, then the memory of '$a' can be shared. But it will only remain shared until '$a' is changed. When that happens, the changed section will be copied and start to take up RAM.
Whether you can measure how much memory is copy-on-write over-committed I do not know. But at least this explains your over-counting.
Just quickly calculate the sum of the processes.
On Mac:
chrome://system/
and select all reported in mem_usagepython
, CMD+V, EnterEt voila! "Easy"... 🤓😅
PS - Shortcut ninjas & 80s/90s Fighting-game players should have no problem with this solution 🤖🕹💾
I found a solution with vim and awk. Open chrome://system, expand mem_usage, copy to vim and execute the regexp:
:%s/\D*\(\d*\).MB.*/\1
This leaves only the numbers before MB. Save the file and execute
cat file | awk '{sum += $1} END {print sum}'
I could not convert the vim regexp code to sed.
There is USS which is available cross platforms
The USS (Unique Set Size) is the memory which is unique to a process and which would be freed if the process was terminated right now.
psutil>4.0 Python library can access it
Here is I would use it
sudo python3 -c "import psutil;print(sum(p.memory_full_info().uss for p in psutil.Process(pid=292).children())/1024/1024);"
where pid=292 is PID of most outer process from Activity Monitor
I knew that chrome/chromium had a task manager, but it doesn't give the total memory used. It turns out that the "Stats for nerds" link in the task manager leads to chrome://memory-redirect/ which does list the total memory used. It would be nice to have external validation of these numbers, as well as a way to get the information on the command line so more could be done with it, but this seems to be the best way available.