Let's say i have 20 users logged on my linux box. How can I know how much memory each of them is using?
|
feedback
|
|
You could try using smem (see ELC2009: Visualizing memory usage with smem for more information). In particular, | |||||||||||
feedback
|
|
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. | |||||
feedback
|
|
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. | |||
|
feedback
|
|
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.
| |||
feedback
|
|
You may try something like:
ps auxU maxwell | awk '{memory +=$4}; END {print memory }'
| ||||
feedback
|
|
This bash script is probably ugly as hell, but thank you for the exercize, 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. | |||
feedback
|
|
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:
| |||
|
feedback
|