0

I'm trying to find out total memory used by all PHP processes on my CentOS server. After some grepping and awking this is my final command.

ps -e | grep php | awk '{print $1}' | xargs pmap | grep total | awk '{print $2}' | sed 's/K//' | awk '{SUM += $1} END {print SUM/1024}'

Now, theoretically this should be working, as I took the total ram output in K, summed it then divided and that's my MB's. Problem is that's returning

12493.5

That's 12GB! There is no way they are using 12GB as the server only has 4GB.

EDIT: According to the manpage of pmap the -x switch shows extended information.

http://linux.die.net/man/1/pmap

There is a column in this view called Dirty. Is this the right column? When I awk out on the Dirty column I get:

1294.1

That would make more sense to me. But I don't know if the Dirty column is the right one or not.

jfreak53
  • 163
  • 1
  • 4
  • 27
  • 1
    you are counting shared and virtual memory too - i think that is the issue here... – Pascal Schmiel May 14 '13 at 14:39
  • Any way to tell `pmap` not to count virtual? Or is there another command to get memory usage other than `pmap` that won't display virtual? – jfreak53 May 14 '13 at 14:40
  • none I'm aware of but it should be possible to get the residential memory from a process. it's up to someone else or google to mention a way to do so :) – Pascal Schmiel May 14 '13 at 14:43

1 Answers1

1

Try to use:

ps avx

and sum up the amount in the column "RSS"

Pascal Schmiel
  • 1,738
  • 12
  • 17