LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-12-2018, 02:21 AM   #1
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Rep: Reputation: 56
How to find total memory used by a process?


Hello

I need to find the total memory used by the Google Chrome browser. How to get that? The top command shows the processes individually but not total.

What I've come up with is this
Code:
$ pmap $(pidof "chrome") | tail -n1 | awk '{print $2}'
1620660K
Not sure how much accurate is this.

Any other method(s) that I can find the total memory used by Chrome browser?

Thanks
 
Old 11-12-2018, 04:02 AM   #2
lougavulin
Member
 
Registered: Jul 2018
Distribution: Slackware,x86_64,current
Posts: 279

Rep: Reputation: 100Reputation: 100
pmap seems to be the most accurate and still quite simple way to do.
But I think :
Code:
pmap -x PID
is easier.

Otherwise, you will need to use a profiler like valgrind.
 
1 members found this post helpful.
Old 11-12-2018, 04:53 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Into the rabbit hole ...
Try this instead - and see if you can figure out what you really want to know.
Code:
ps -C chrome -o uid,pid,rss,vsz,comm
 
1 members found this post helpful.
Old 11-12-2018, 05:35 AM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
You can also use top:
Code:
PID  USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
3292 stack     20   0 2010648  82940   8708 S   5.6  1.0  12:51.49 ceilometer-agen
Now the million dollar question is - what does "total memory" mean? Virtual memory (VIRT)? Physical memory (RES)? Does it include shared memory (SHR)? You decide.

EDIT I didn't read your question thoroughly. You want to sum up the memory usage of all chrome processes, which top is not really the right tool for.

Last edited by berndbausch; 11-12-2018 at 05:38 AM.
 
1 members found this post helpful.
Old 11-12-2018, 08:44 AM   #5
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by berndbausch View Post
You can also use top:
Code:
PID  USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
3292 stack     20   0 2010648  82940   8708 S   5.6  1.0  12:51.49 ceilometer-agen
Now the million dollar question is - what does "total memory" mean? Virtual memory (VIRT)? Physical memory (RES)? Does it include shared memory (SHR)? You decide.

EDIT I didn't read your question thoroughly. You want to sum up the memory usage of all chrome processes, which top is not really the right tool for.
Just Physical memory (RES).
 
Old 11-12-2018, 08:47 AM   #6
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by syg00 View Post
Into the rabbit hole ...
Try this instead - and see if you can figure out what you really want to know.
Code:
ps -C chrome -o uid,pid,rss,vsz,comm
I guess I've to write a shell script that clips the third column and add it to find the sum. No built-in command exist?
 
Old 11-12-2018, 09:07 AM   #7
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
I've come up with this command. Is this the correct way? Is there a way to display RSS in bytes rather that default kb?

Code:
$ ps -C chrome -o comm,rss
COMMAND           RSS
chrome          226852
chrome          35500
chrome          10652
chrome          66652
chrome          38940
chrome          48032
chrome          144332
chrome          45944
chrome          72816
chrome          54748
chrome          79804
chrome          51564
chrome          114244
chrome          108788
chrome          86808
chrome          99424
chrome          121960
chrome          61384
chrome          74092
chrome          131356
chrome          23444

$ ps --no-headers -C chrome -o rss | awk '{ hr=$1*1024 ; printf("%15d\n",hr) }' | paste -sd+ | bc | numfmt --to=iec
1.7G
 
Old 11-12-2018, 09:21 AM   #8
lougavulin
Member
 
Registered: Jul 2018
Distribution: Slackware,x86_64,current
Posts: 279

Rep: Reputation: 100Reputation: 100
I have always heard that ps was not the good tool to know how much memory use a process.

And I guess this is why :
Man ps :
Quote:
The SIZE and RSS fields don't count some parts of a process including the page tables, kernel
stack, struct thread_info, and struct task_struct. This is usually at least 20 KiB of memory
that is always resident. SIZE is the virtual size of the process (code+data+stack).
That's why I prefer pmap.
 
Old 11-12-2018, 09:26 AM   #9
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by lougavulin View Post
I have always heard that ps was not the good tool to know how much memory use a process.

And I guess this is why :
Man ps :

That's why I prefer pmap.
Even I was wondering why three different results.

Code:
$ free -h
              total        used        free      shared  buff/cache   available
Mem:           7.6G        1.6G        4.1G         24M        1.8G        5.6G
Swap:          8.0G          0B        8.0G

$ ps --no-headers -C chrome -o rss | awk '{ hr=$1*1024 ; printf("%15d\n",hr) }' | paste -sd+ | bc | numfmt --to=iec
2.2G

$ pmap $(pidof "chrome") | tail -n1 | awk '{print $2}'
1575424K
 
Old 11-12-2018, 03:55 PM   #10
JeremyBoden
Senior Member
 
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,947

Rep: Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511
I tried this with two times firefox running (one of which has two tabs open):-
Code:
free -h
              total        used        free      shared  buff/cache   available
Mem:           7.7G        1.3G        3.1G        129M        3.3G        6.0G
Swap:          4.0G          0B        4.0G

ps --no-headers -C firefox -o rss | awk '{ hr=$1*1024 ; printf("%15d\n",hr) }' | paste -sd+ | bc | numfmt --to=iec
536M

pmap $(pidof "firefox") | tail -n1 | awk '{print $2}'
3098548K
All completely different!
 
Old 11-12-2018, 11:35 PM   #11
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
I think I finally figured it out on how to get an almost precise total memory of a group of processes.

Google-Chrome with 5 tabs open, each with OneNote online notebook, 1 instance of Gedit text editor and 1 instance of gnome-terminal.

Code:
$ free -h
              total        used        free      shared  buff/cache   available
Mem:           7.6G        1.9G        5.0G         30M        643M        5.3G
Swap:          8.0G          0B        8.0G

$ sudo smem -tk -U $USER -P chrome
  PID User     Command                         Swap      USS      PSS      RSS 
 6616 testr    /opt/google/chrome/chrome-s        0   116.0K   149.0K   680.0K 
 6620 testr    /opt/google/chrome/chrome-s        0   120.0K   153.0K   688.0K 
 6623 testr    /opt/google/chrome/chrome -        0   120.0K   815.0K    10.4M 
 6621 testr    /opt/google/chrome/nacl_hel        0   860.0K   875.0K     1.7M 
 7391 testr    /opt/google/chrome/chrome -        0     4.5M     5.4M    23.2M 
 6618 testr    /opt/google/chrome/chrome -        0     3.7M     8.3M    34.7M 
 6751 testr    /opt/google/chrome/chrome -        0     9.0M    10.5M    38.6M 
 7019 testr    /opt/google/chrome/chrome -        0     9.6M    11.3M    40.7M 
 6764 testr    /opt/google/chrome/chrome -        0    14.5M    16.5M    47.8M 
 6830 testr    /opt/google/chrome/chrome -        0    14.7M    16.7M    48.1M 
 6795 testr    /opt/google/chrome/chrome -        0    15.2M    16.8M    46.1M 
 6820 testr    /opt/google/chrome/chrome -        0    17.5M    19.7M    52.3M 
 6823 testr    /opt/google/chrome/chrome -        0    30.7M    32.5M    63.0M 
 6813 testr    /opt/google/chrome/chrome -        0    32.0M    34.9M    70.4M 
 6649 testr    /opt/google/chrome/chrome -        0    30.6M    39.0M    63.3M 
 7124 testr    /opt/google/chrome/chrome -        0    69.1M    71.4M   105.2M 
 6972 testr    /opt/google/chrome/chrome -        0    77.2M    79.6M   114.0M 
 6771 testr    /opt/google/chrome/chrome -        0    82.9M    85.0M   117.0M 
 6608 testr    /opt/google/chrome/chrom           0   188.2M   196.3M   230.8M 
 7308 testr    /opt/google/chrome/chrome -        0   209.6M   214.8M   261.9M 
 7140 testr    /opt/google/chrome/chrome -        0   216.4M   221.6M   269.0M 
 7359 testr    /opt/google/chrome/chrome -        0   220.1M   225.4M   272.8M 
 7219 testr    /opt/google/chrome/chrome -        0   220.4M   225.6M   272.9M 
 6720 testr    /opt/google/chrome/chrome -        0   220.4M   225.9M   273.7M 
-------------------------------------------------------------------------------
   24 1                                           0     1.6G     1.7G     2.4G
Closing Google-Chrome and after waiting 10 seconds,

Code:
$ free -h
              total        used        free      shared  buff/cache   available
Mem:           7.6G        292M        6.7G         11M        615M        7.0G
Swap:          8.0G          0B        8.0G
So, this one deducted chrome memory properly.

@JeremyBoden, can you test with Firefox, as I don't use firefox.

Thanks
 
Old 11-13-2018, 01:48 AM   #12
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
I would say no, that is not true. I suggest you to read this: www.linuxatemyram.com just to understand better how memory is handled.
Furthermore the used ram may change during the script you use, so probably that (the result) is simply outdated immediately.
 
2 members found this post helpful.
Old 11-13-2018, 02:05 AM   #13
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Quote:
Originally Posted by ddenial View Post
I think I finally figured it out on how to get an almost precise total memory of a group of processes.
Good for you - I'd forgotten about smem to be honest.
pss is provided by the kernel (these days) to apportion shared library usage to users, rather than charging everybody who has a reference for the full amount of every library. There are a couple of utilities that attempt to report it - be happy with the one you found.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get total cpu usage, total memory usage and available memory Chiba Linux - Software 1 11-15-2014 04:36 PM
determine total memory used by some user/process optimuz Linux - Newbie 6 08-13-2009 07:30 AM
total memory used of postgresql okar Linux - General 5 07-25-2009 01:49 PM
getting total memory used gecoool Programming 8 10-20-2005 02:23 AM
Help Configuring the Memory Used by a Process in RedHat? (Cache Memory on CPU) geogecko Linux - General 3 02-23-2005 03:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration