Quote:
Originally Posted by forumbala88
Hi friends
What command we have to use to find the ram utilisation for a particular user in linux
Regards
forumbala
|
Well the question is not correct as per my knowledge, because you look for RAM utilization per process and not per user. What you can do is you find all the processes running as a particlular user and then you can find memory/RAM utilization for all those process. There are multiple ways you can do that. YOu can use Top command to find the top processes consuming the memory (Virt and RES). If you want to know about a aprticular process use the pmap command like below
Code:
pmap <pid>
pmap 23305
Out put would be something like this.
23305: java -Dmule.home=/mule/mule -Dmule.base=/mule/mule -Djava.net.preferIPv4Stack=TRUE -XX:MaxPermSize=256m -Djava.endorsed.dirs=/mule/mule/lib/endorsed -Docs.env=prod -Dmule.mmc.bind.port=1521 -Xms6144m -Xmx6144m -Djava.library.path=%LD_LIBRARY_PATH%:/mule/mule/lib/boot -classpath %MULE_LIB%:/mule/mule/conf:/mule/mule/lib/boot/commons-cli-1.2.jar:/mule/mule/lib/boot/commons-codec-1.3-osgi.jar:/mule/mule/lib/boot/jul-to-slf4j-1.6.1.jar:/mule/mule/lib/boot/licm-1.1.2.jar:/mule/mule/lib/boot/log4j-1.2.16.jar:/mu
0000000040000000 36K r-x-- /mule/jdk1.6.0_31/bin/java
0000000040108000 8K rwx-- /mule/jdk1.6.0_31/bin/java
000000004010a000 12K ----- [ anon ]
000000004010d000 1016K rwx-- [ anon ]
000000004020b000 12K ----- [ anon ]
000000004020e000 1016K rwx-- [ anon ]
000000004030c000 12K ----- [ anon ]
000000004030f000 1016K rwx-- [ anon ]
000000004040d000 12K ----- [ anon ]
0000000040410000 1016K rwx-- [ anon ]
000000004062d000 12K ----- [ anon ]
0000000040630000 1016K rwx-- [ anon ]
00000000407af000 12K ----- [ anon ]
00000000407b2000 1016K rwx-- [ anon ]
00000000408b0000 12K ----- [ anon ]
00000000408b3000 1016K rwx-- [ anon ]
00000000409b1000 12K ----- [ anon ]
00000000409b4000 1016K rwx-- [ anon ]
0000000040ab2000 12K ----- [ anon ]
0000000040ab5000 1016K rwx-- [ anon ]
0000000040bb3000 12K ----- [ anon ]
0000000040bb6000 1016K rwx-- [ anon ]
0000000040d3c000 12K ----- [ anon ]
0000000040d3f000 1016K rwx-- [ anon ]
..........
..........
00002ae6a6e67000 1748K rwx-- /mule/jdk1.6.0_31/jre/lib/amd64/server/libjvm.so
00002ae6a701c000 232K rwx-- [ anon ]
00007fff6ef45000 84K rwx-- [ stack ]
00007fff6effc000 16K r-x-- [ anon ]
ffffffffff600000 8192K ----- [ anon ]
total 7684108K
Last line will show you the total memmory usage for the process.
You can also use the following code to find the 20 process using maximum RAM
Code:
for i in /proc/*/smaps ; do awk '/Rss/ {sum += $2}; END{if (sum>0) print FILENAME " Total: " sum/1024}' $i; done | sort -nr -k 3 | head -20
Answering your question finally this is what you would need to do get the memory utilzation for the processes run by a particular user. The below code will give top 20 memory consuming proceeses for that user
Code:
ps -U <user_name> -u <user_name>| awk '{print $1}' >pid.list
for i in `cat pid.list` ; do awk '/Rss/ {sum += $2}; END{if (sum>0) print FILENAME " Total: " sum/1024}' /proc/$i/smaps 2> /dev/null; done|sort -nr -k 3|head -20
And the below code will give you the total memory used by all the processes being run by that particular user
Code:
for i in `cat pid.list` ; do awk '/Rss/ {sum += $2}; END{if (sum>0) print FILENAME " Total: " sum/1024}' /proc/$i/smaps 2> /dev/null; done| awk '{Avg += $3} END {print "Total memory: "Avg}'
Again this can be automated for any user using positional parameter in a shell script.