Some times it’s required for us to know what is the RAM used by an application. Suppose in your machine Apache service or Mysql service is consuming up all your RAM. So how to check it? Is there any direct command to do this? The answer to this is no. We have to use two commands to do this. Here is the way to see what is the ram used by a particular Application.

To see all the process run by a particular application, We can user pgrep(process grep).
#pgrep application-name

Example(in Ubuntu)
#pgrep apache

To see all the memory used by a process we use pmap(process mapping ).
#pmap pid-of-that-application

Example :
# pmap 1946
1946: /usr/sbin/apache2 -k start
00110000 28K r-x– /lib/tls/i686/cmov/
00117000 4K r—- /lib/tls/i686/cmov/
00118000 4K rw— /lib/tls/i686/cmov/
00119000 8K r-x– /usr/lib/apache2/modules/
0011b000 4K r—- /usr/lib/apache2/modules/
0011c000 4K rw— /usr/lib/apache2/modules/
0011d000 8K r-x– /usr/lib/apache2/modules/
0011f000 4K r—- /usr/lib/apache2/modules/
00120000 4K rw— /usr/lib/apache2/modules/
00121000 16K r-x– /usr/lib/apache2/modules/
00125000 4K r—- /usr/lib/apache2/modules/
00126000 4K rw— /usr/lib/apache2/modules/
00129000 76K r-x– /lib/tls/i686/cmov/
0013c000 4K r—- /lib/tls/i686/cmov/
0013d000 4K rw— /lib/tls/i686/cmov/
0013e000 8K rw— [ anon ]
00140000 32K r-x– /usr/lib/apache2/modules/
00148000 4K r—- /usr/lib/apache2/modules/
00149000 4K rw— /usr/lib/apache2/modules/
0014a000 80K r-x– /lib/
0015e000 4K r—- /lib/
0015f000 4K rw— /lib/
00160000 8K r-x– /lib/
00162000 4K r—- /lib/
00163000 4K rw— /lib/
00164000 8K r-x– /lib/
00166000 4K r—- /lib/
00167000 4K rw— /lib/
00168000 24K r-x– /usr/lib/php5/20060613+lfs/
0016e000 4K r—- /usr/lib/php5/20060613+lfs/
0016f000 4K rw— /usr/lib/php5/20060613+lfs/
00171000 24K r-x– /lib/tls/i686/cmov/
00177000 4K r—- /lib/tls/i686/cmov/
00178000 4K rw— /lib/tls/i686/cmov/
00179000 36K r-x– /lib/tls/i686/cmov/
00182000 4K r—- /lib/tls/i686/cmov/
00183000 4K rw— /lib/tls/i686/cmov/
00184000 144K r-x– /lib/tls/i686/cmov/
001a8000 4K r—- /lib/tls/i686/cmov/
001a9000 4K rw— /lib/tls/i686/cmov/
001aa000 40K r-x– /usr/lib/php5/20060613+lfs/
001b4000 4K r—- /usr/lib/php5/20060613+lfs/
001b5000 4K rw— /usr/lib/php5/20060613+lfs/
001bf000 28K r-x– /usr/lib/apache2/modules/
001c6000 4K r—- /usr/lib/apache2/modules/
001c7000 4K rw— /usr/lib/apache2/modules/
001c8000 92K r-x– /usr/lib/php5/20060613+lfs/
001df000 4K r—- /usr/lib/php5/20060613+lfs/
001e0000 8K rw— /usr/lib/php5/20060613+lfs/
001e4000 4K r-x– [ anon ]
001f0000 188K r-x– /lib/
0021f000 4K r—- /lib/
00220000 4K rw— /lib/
00221000 76K r-x– /usr/lib/php5/20060613+lfs/
00234000 4K r—- /usr/lib/php5/20060613+lfs/
00235000 8K rw— /usr/lib/php5/20060613+lfs/
00241000 4K r-x– /usr/lib/apache2/modules/
00242000 4K —– /usr/lib/apache2/mod
00243000 4K r—- /usr/lib/apache2/modules/
00244000 4K rw— /usr/lib/apache2/modules/
00246000 64K r-x– /lib/tls/i686/cmov/
00256000 4K r—- /lib/tls/i686/cmov/
00257000 4K rw— /lib/tls/i686/cmov/
00258000 8K rw— [ anon ]
00260000 36K r-x– /lib/tls/i686/cmov/
00269000 4K r—- /lib/tls/i686/cmov/
0026a000 4K rw— /lib/tls/i686/cmov/
0026b000 156K rw— [ anon ]
00292000 112K r-x– /lib/
002ae000 4K r—- /lib/
002af000 4K rw— /lib/
002b9000 12K r-x– /lib/
002bc000 4K r—- /lib/
002bd000 4K rw— /lib/
002be000 260K r-x– /lib/i686/cmov/
002ff000 4K —– /lib/i686/cmov/
00300000 4K r—- /lib/i686/cmov/
00301000 12K rw— /lib/i686/cmov/
00304000 152K r-x– /usr/lib/
0032a000 4K —– /usr/lib/
0032b000 4K r—- /usr/lib/
0032c000 4K rw— /usr/lib/
00349000 144K r-x– /lib/
0036d000 8K r—- /lib/
0036f000 4K rw— /lib/
00385000 4K r-x– /usr/lib/apache2/modules/
00386000 4K r—- /usr/lib/apache2/modules/
00387000 4K rw— /usr/lib/apache2/modules/
003ec000 160K r-x– /usr/lib/
00414000 4K r—- /usr/lib/
00415000 4K rw— /usr/lib/
00416000 636K r-x– /usr/lib/
004b5000 4K —– /usr/lib/
004b6000 20K r—- /usr/lib/
004bb000 4K rw— /usr/lib/
004e3000 8K r-x– /usr/lib/apache2/modules/
004e5000 4K —– /usr/lib/apache2/modules/
004e6000 4K r—- /usr/lib/apache2/modules/
004e7000 4K rw— /usr/lib/apache2/modules/
00501000 8K r-x– /usr/lib/apache2/modules/
00503000 4K r—- /usr/lib/apache2/modules/
00504000 4K rw— /usr/lib/apache2/modules/
0060f000 8K r-x– /usr/lib/apache2/modules/
00611000 4K r—- /usr/lib/apache2/modules/
00612000 4K rw— /usr/lib/apache2/modules/
006f6000 4K r-x– /usr/lib/apache2/modules/
006f7000 4K r—- /usr/lib/apache2/modules/
006f8000 4K rw— /usr/lib/apache2/modules/
006f9000 1428K r-x– /usr/lib/
0085e000 8K r—- /usr/lib/
00860000 4K rw— /usr/lib/
00907000 20K r-x– /usr/lib/apache2/modules/
0090c000 4K r—- /usr/lib/apache2/modules/
0090d000 4K rw— /usr/lib/apache2/modules/
00950000 4K r-x– /usr/lib/apache2/modules/
00951000 4K r—- /usr/lib/apache2/modules/
00952000 4K rw— /usr/lib/apache2/modules/
0099e000 4K r-x– /usr/lib/apache2/modules/
0099f000 4K r—- /usr/lib/apache2/modules/
009a0000 4K rw— /usr/lib/apache2/modules/
00a13000 372K r-x– /usr/lib/apache2/mpm-prefork/apache2
00a71000 8K r—- /usr/lib/apache2/mpm-prefork/apache2
00a73000 8K rw— /usr/lib/apache2/mpm-prefork/apache2
00a75000 12K rw— [ anon ]
00ad5000 24K r-x– /usr/lib/
00adb000 4K r—- /usr/lib/
00adc000 4K rw— /usr/lib/
00b28000 132K r-x– /usr/lib/
00b49000 4K r—- /usr/lib/
00b4a000 4K rw— /usr/lib/
00b66000 64K r-x– /lib/
00b76000 4K r—- /lib/
00b77000 4K rw— /lib/
00b90000 16K r-x– /usr/lib/apache2/modules/
00b94000 4K r—- /usr/lib/apache2/modules/
00b95000 4K rw— /usr/lib/apache2/modules/
00ba6000 164K r-x– /usr/lib/
00bcf000 4K r—- /usr/lib/
00bd0000 4K rw— /usr/lib/
00bf5000 12K r-x– /usr/lib/apache2/modules/
00bf8000 4K r—- /usr/lib/apache2/modules/
00bf9000 4K rw— /usr/lib/apache2/modules/
00c7e000 40K r-x– /lib/tls/i686/cmov/
00c88000 4K r—- /lib/tls/i686/cmov/
00c89000 4K rw— /lib/tls/i686/cmov/
00ce9000 1272K r-x– /lib/tls/i686/cmov/
00e27000 8K r—- /lib/tls/i686/cmov/
00e29000 4K rw— /lib/tls/i686/cmov/
00e2a000 12K rw— [ anon ]
00e67000 84K r-x– /lib/tls/i686/cmov/
00e7c000 4K r—- /lib/tls/i686/cmov/
00e7d000 4K rw— /lib/tls/i686/cmov/
00e7e000 8K rw— [ anon ]
00f69000 108K r-x– /lib/
00f84000 4K r—- /lib/
00f85000 4K rw— /lib/
00f9d000 8K r-x– /lib/tls/i686/cmov/
00f9f000 4K r—- /lib/tls/i686/cmov/
00fa0000 4K rw— /lib/tls/i686/cmov/
00fa1000 5036K r-x– /usr/lib/apache2/modules/
0148c000 4K —– /usr/lib/apache2/modules/
0148d000 68K r—- /usr/lib/apache2/modules/
0149e000 148K rw— /usr/lib/apache2/modules/
014c3000 20K rw— [ anon ]
01cc1000 1204K r-x– /lib/i686/cmov/
01dee000 32K r—- /lib/i686/cmov/
01df6000 52K rw— /lib/i686/cmov/
01e03000 16K rw— [ anon ]
03087000 1716K r-x– /usr/lib/
03234000 12K r—- /usr/lib/
03237000 276K rw— /usr/lib/
0327c000 4K rw— [ anon ]
06147000 1160K r-x– /usr/lib/
06269000 4K —– /usr/lib/
0626a000 16K r—- /usr/lib/
0626e000 4K rw— /usr/lib/
0626f000 4K rw— [ anon ]
21436000 2820K rw— [ anon ]
b6d8a000 4K —– [ anon ]
b6d8b000 10240K rw— [ anon ]
b77cc000 16K rw— [ anon ]
b77d0000 64K rw-s- /dev/zero (deleted)
b77e0000 8K rw— [ anon ]
bfc89000 84K rw— [ stack ]
total 29964K

When we see the output of this command, it will give details as follows
First column will show memory location
2.second column will show RAM use of each file opened by this process
3.Third column will show rw permission.
4.Last one will show what are the files opened by this process
5.And last line of this output will show total size used, here it is 2088K

So you have to run this command on all the process of apache application. If you see the last line it’s showing total RAM used by this PID. Which is ~30MB. Which is nothing but total RAM used by this PID

Suppose if you want to see all the memory(RAM), files opened by apache use below command
#pmap `pgrep apache`

If you execute above command it will give pages and pages of information which you don’t need, to get answer in presided way. Just grep last line with “total”.

Example :
# pmap `pgrep apache` | grep total
total 29964K
total 29964K
total 29964K
total 29964K
total 29964K
total 29964K
total 29964K

Please share your thoughts if you have more better options to check RAM use by an application:-)

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.