Tell me more ×
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.

I want to get a full added amount of memory usage for a particular process. Here say I want to have the total amount of memory taken by httpd. So if I do a tail command as "tail -M" I get



  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                 
10036 mysql     20   0  417m  76m 3820 S  0.3 15.5   0:13.55 mysqld                                                                                  
10453 apache    20   0  229m  67m  42m S  0.0 13.7   0:10.81 httpd                                                                                   
10447 apache    20   0  230m  64m  38m S  0.0 13.0   0:11.54 httpd                                                                                   
10479 apache    20   0  226m  64m  42m S  0.0 13.0   0:09.75 httpd                                                                                   
10478 apache    20   0  230m  63m  38m S  0.0 12.9   0:11.02 httpd                                                                                   
10451 apache    20   0  230m  63m  37m S  0.0 12.8   0:10.37 httpd                                                                                   
 9599 apache    20   0  227m  61m  38m S  0.0 12.4   0:10.80 httpd                                                                                   
10454 apache    20   0  226m  60m  38m S  0.0 12.2   0:09.56 httpd                                                                                   
10476 apache    20   0  225m  58m  38m S  0.0 11.9   0:09.87 httpd                                                                                   
10332 apache    20   0  228m  50m  24m S  0.0 10.2   0:13.73 httpd                                                                                   
10445 apache    20   0  220m  42m  24m S  0.0  8.5   0:10.17 httpd                                                                                   
  637 root      10 -10 32816  25m 1712 S  0.0  5.2   0:00.01 iscsiuio                                                                                
  652 root      10 -10  5128 2972 1876 S  0.0  0.6   0:05.86 iscsid                                                                                  
 9592 root      20   0  207m 2872  900 S  0.0  0.6   0:00.39 httpd                                                                                   
10196 nobody    20   0  136m 2408  500 S  0.0  0.5   0:00.79 memcached              

In this case I want to have the "VIRT", "RES", "SHR", "%CUP", & "%MEM" totally as added for each rows of the output.

Is there anyway I can do that?

share|improve this question

2 Answers

Try doing this using :

top -b -n1 -c | 
    awk -vOFS=$'\t' '
        $2 == "apache"{
            virt+=$5; res+=$6; shr+=$7; cpu+=$9; mem+=$10; count++
        }
        END{
            print "virt", "res", "shr", "cpu", "mem"
            print virt, res, shr, cpu/count, mem/count
        }
    '
share|improve this answer
thanks, I will have a look at it. – Aneek Mukhopadhyay Jan 27 at 6:36
Please look up what each of the fields really mean. Sure, ypu can add them up, average them, slice them, dice them, but that doesn't make them mean something else. – vonbrand Jan 29 at 15:33
Feel free to adapt it for the real world. – sputnick Jan 30 at 11:53

The memory usage by a process isn't a well-defined concept, there are shared memory areas (shared libraries, several processes sharing the executable, parent/child sharing non-modified data). If you now take threads, by definition all threads share the resources of the containing process.

share|improve this answer

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.