Let's say i have 20 users logged on my linux box. How can I know how much memory each of them is using?
|
You could try using smem (see ELC2009: Visualizing memory usage with smem for more information). In particular, |
|||||||||||
|
|
Ignoring shared memory issues, here's a quick script that gives you RSS and VMEM for all logged in users, sorted by vmem, and organized into cute columns:
|
|||
|
|
|
That's a tricky question. You could easily sum up the total RSS+swap amounts in "ps" output, but what about shared memory? Different users could easily share the same code page if they're running the same process. Who do you account that to? What about buffers and cache? It really depends on how accurate you want your results to be. The more accurate you want, the harder it will be. |
|||||
|
|
To get sum of RSS I think the following works. This would be to get the sum of RSS for the users kbrandt and root.
|
|||
|
|
I'm not sure how to report memory usage by user but if you're concerned about controlling their usage then you should look up ulimit. It will allow you to set hard and soft limits on a per user/group basis for memory and other resources on your system. |
|||
|
|
|
You may try something like:
ps auxU maxwell | awk '{memory +=$4}; END {print memory }'
|
||||
|
|
This bash script is probably ugly as hell, but thank you for the exercise, my bash was (is) getting rusty!
Result:
Please comment/correct and I will update the answer. Also I use the rss memory output from PS, as others have discussed there are pros/cons to using this value. |
|||||
|
|
smem wasn't available on my system, and Dave's script didn't work for some reason, so I wrote this ugly Perl oneliner to process ps output:
Note that some users were identified using their UID rather than their username. You could deal with this by parsing usernames from /etc/passwd, using the uglier:
|
|||
|
|
|
Looking for the same, I figured out this
to print processes ordered by mem, grouped by user (column1, the $1), you can group by other things, and sum other things, changing $1 and $4
I was happy to find the solution, just wanted to share. |
|||
|
|
|
Using Bash Script
OUTPUT
|
|||
|
|