LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to display RAM usage per user using top command options (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-display-ram-usage-per-user-using-top-command-options-4175505164/)

MLS 05-15-2014 11:35 PM

How to display RAM usage per user using top command options
 
Hi! I've been trying to find an option to display the exact ram usage value of the user that has the highest. Top command only displays the whole process but I need a "per user" value. Please help :(
:)

LinBox2013 05-15-2014 11:41 PM

Quote:

Originally Posted by MLS (Post 5171786)
Hi! I've been trying to find an option to display the exact ram usage value of the user that has the highest. Top command only displays the whole process but I need a "per user" value. Please help :(
:)

Install smem and do a smem -u.

Or this: (echo "user rss(KiB) vmem(KiB)";
for user in $(users | tr ' ' '\n' | sort -u); do
echo $user $(ps -U $user --no-headers -o rss,vsz \
| awk '{rss+=$1; vmem+=$2} END{print rss" "vmem}')
done | sort -k3
) | column -t

MLS 05-15-2014 11:49 PM

Do I type those directly in unix?

---------- Post added 05-15-14 at 11:49 PM ----------

Quote:

Originally Posted by LinBox2013 (Post 5171788)
Install smem and do a smem -u.

Or this: (echo "user rss(KiB) vmem(KiB)";
for user in $(users | tr ' ' '\n' | sort -u); do
echo $user $(ps -U $user --no-headers -o rss,vsz \
| awk '{rss+=$1; vmem+=$2} END{print rss" "vmem}')
done | sort -k3
) | column -t

Do I type these directly on Unix?

LinBox2013 05-15-2014 11:53 PM

Quote:

Originally Posted by MLS (Post 5171794)
Do I type those directly in unix?

---------- Post added 05-15-14 at 11:49 PM ----------



Do I type these directly on Unix?

Into a terminal.

MLS 05-16-2014 01:20 AM

Quote:

Originally Posted by LinBox2013 (Post 5171798)
Into a terminal.

It does not work.

MLS 05-16-2014 01:24 AM

How will I see the RAM usage of other users also?

geedoubleya 05-16-2014 09:09 AM

Quote:

Originally Posted by LinBox2013 (Post 5171788)
Install smem and do a smem -u.

Or this: (echo "user rss(KiB) vmem(KiB)";
for user in $(users | tr ' ' '\n' | sort -u); do
echo $user $(ps -U $user --no-headers -o rss,vsz \
| awk '{rss+=$1; vmem+=$2} END{print rss" "vmem}')
done | sort -k3
) | column -t

This script is using an empty variable (users) which will need to be populated before the script is run for it to work:
users=`ps -eouser --sort user --noheader|uniq`
Or subsititue the command string in place of the $users entry.

An alternative string using less commands with less elegant output could be:
ps -eouser,size --sort user --no-header|awk '!($1 in a){a[$1];print rec,sum;sum=""}{sum+=$2;rec=$1} END {print rec,sum}'

The values are in KB. and represent the currently allocated and intented to be allocated memory not the virtual memory.
However This is still not ideal as it will only provide a rough value.

Cheers

Habitual 05-16-2014 11:25 AM

Quote:

Originally Posted by MLS (Post 5171794)
Do I type these directly on Unix?

Unix or Linux?

jpollard 05-17-2014 09:25 PM

Quote:

Originally Posted by MLS (Post 5171786)
Hi! I've been trying to find an option to display the exact ram usage value of the user that has the highest. Top command only displays the whole process but I need a "per user" value. Please help :(
:)

You want to sort on the RES field (resident memory used), or the VIRT (total memory used by teh process - being swap + the in memory resident pages. (use the < and > characters to move the sort column left or right).


All times are GMT -5. The time now is 03:20 AM.