Friday, August 6, 2010

Memory Utilization of Individual Process on Linux

One of my colleague found this easy way to figure of memory utilization of each process running on linux machine without root access though :)

To calculate for each process on linux we do the following:

We have a java process runing on 7804 . Hence pid is 7804

[test@appsupport /]$ cat /proc/7804/statm

124 123 108 6 1 117 10

[test@appsupport /]$


In this 124 is in pages, to calculate it to KB multiply It with 4 ( 124*4 => 496 KB ).

################
Script to calculate the total memory for n number of processes.
################
Below we are calculating for all root process running.

ps auxwww | grep -i root | awk '{ print $2}' > /tmp/txt.txt

for i in `cat /tmp/txt.txt`; do cd /proc/;cd $i;a=`cat statm | awk '{ print $1}'`; let a*=4; echo $a memory utilized by $i "completed";let b=b+a;cd ../; done

No comments:

Post a Comment