Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

With ps command I can find out how much memory each program uses:

ps -u mertnuhoglu -o pcpu,rss,pid,command

Is it possible to find out the sums of each type of resource usage as well, easily?

share|improve this question
1  
Note that quantifying memory usage is tricky, because some memory is shared between processes. The sum of the figures you get this way will be an overestimate. RSS is only a rough estimate of how much memory an application uses anyway (it doesn't take into account swapped-out memory or file buffers). –  Gilles Oct 1 '11 at 22:05

2 Answers 2

up vote 6 down vote accepted

You could sum the usage columns with awk:

ps --no-headers -u $USER -o pcpu,rss | awk '{cpu += $1; rss += $2} END {print cpu, rss}'

You might also be interested in the free command for memory usage:

$ free
             total       used       free     shared    buffers     cached
Mem:       2055480    1806596     248884          0      14016     346276
-/+ buffers/cache:    1446304     609176
Swap:      2097148     132980    1964168

The output is in kilobytes (use free -m for megabytes). In particular, the used, +/- buffers/cache entry is something like the total physical memory used (by everyone).

share|improve this answer

You can try:

$ ps -eo vsz,comm= | awk 'NR>1{u[$2]+=$1}END{for(i in u) print u[i]"="i}' 
share|improve this answer
1  
Do not only paste command. please also mansion/explain how this command use to solve this question. –  Tejas Dec 18 at 9:54

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.