Script to get ram memory and total memory usage of a particular user in Linux.

Here we will check how to get RSS(Resident Set size) memory i.e. total KBs of memory usage in RAM, and VSZ(Virtual Size) memory i.e. total memory usage including ram, swap, shared memory, etc for a particular User in Linux.

This small script is very useful for day to day operations and you can also save this to use from now onwards.

Here is the small command/script that i use.

[root@nglinux ~]# user=saket; \
echo -e "\n############ \n Memory usage of user $user \n RSS \t VSZ"; \
ps -U $user -o rss,vsz --no-headers | \
awk '{rss+=$1; vmem+=$2} END{print rss" "vmem}' | \
awk '{rss2=$1/1024; vmem2=$2/1024} END{print " "rss2" "vmem2}'; \
echo -e "#############";

 ############ 
 Memory usage of user saket 
 RSS 	 VSZ
 3.64453 28.0547
 #############
[root@nglinux ~]# 

In the above script, replace user variable to a valid username instead of saket user on my system.

This is one of the easiest way to get total memory usage and ram usage of different users on a Linux system.

You can use this inside a script to get usage for all users.

I hope you liked the tip.

Do post your valuable comments below and subscribe to our blog for latest blog post updates.

Leave a Reply

Your email address will not be published.