Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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.

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


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

share|improve this question
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
up vote 1 down vote accepted

Try to use:

ps avx

and sum up the amount in the column "RSS"

share|improve this answer
"RSS: resident set size, the non-swapped physical memory that a task has used (in kiloBytes). (alias rssize, rsz)." – Pascal Schmiel May 14 '13 at 14:49
Which column is the RSS column? I count 10 columns but no headers. – jfreak53 May 14 '13 at 14:50
on my system it's the 8th column – Pascal Schmiel May 14 '13 at 14:51
That seems to work, it's returning the same as the pmap command I tried above with -x. Final command is ps avx | grep php | awk '{print $8}' | awk '{SUM += $1} END {print SUM/1024}' – jfreak53 May 14 '13 at 14:52
great. so both of us learned something today :-D – Pascal Schmiel May 14 '13 at 14:53

Your Answer


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.