Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I typed the free command to get the memory usage as follows :

free -m 

output:

enter image description here

I want to use this command to get the same info but for all users for example :

enter image description here

I used this command .. because it easy for me .. to store its output in a variables in a bash scrip ...

share|improve this question
    
Do you mean that you want 'used' to be separated for users? Because total and free are going to be the same. –  Volodya Feb 14 at 15:10
    
Yes I mean 'used' –  Akari Feb 14 at 15:11

2 Answers 2

up vote 5 down vote accepted

free is already based on the system-wide memory usage.

If you want something on a per-user basis, you could try something like:

ps aux | awk 'NR>2{arr[$1]+=$6}END{for(i in arr) print i,arr[i]}'

As a quick explanation of what the awk does:

  • Strips off the first line
  • Iterates through each line and creates an array of every given username. For each of those it adds the sixth column from ps aux (resident set size) and adds them up.
  • After that it just iterates through the array keys to print the content.
share|improve this answer

One option is to use smem Install smem as free does not offer this functionality.

$ sudo smem -u -k -t
User     Count     Swap      USS      PSS      RSS 
daemon       1        0   196.0K   197.0K   360.0K 
rtkit        1        0   304.0K   317.0K     1.4M 
[...]
root        44        0   164.3M   197.7M   284.4M 
gert        88        0     1.7G     1.8G     3.2G 
---------------------------------------------------
           159        0     1.9G     2.1G     3.6G

For explanation on what USS and PSS means, here's an excerpt from the manpage of smem.

            [...] Unshared memory is reported as the USS (Unique Set
   Size).  Shared memory is divided evenly among the processes shar‐
   ing that memory.  The unshared memory (USS) plus a process's pro‐
   portion of shared memory is reported as the PSS (Proportional Set
   Size).  The USS and PSS only include physical memory usage.  They
   do not include memory that has been swapped out to disk.

I suspect RSS is the Residential memory usage also referred to as RES in other utilities. For more information on expression of memory usage see this Q&A on Superuser.com: What I should know about memory management?

share|improve this answer
    
does USS refer to the used memory by this user ?? –  Akari Feb 14 at 15:38
1  
@Akari See my updated answer; I hope this is clear now. It's not a straightforward yes/no to that, because memory management is a bit complicated. –  gertvdijk Feb 14 at 15:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.