10

How can I find the total memory usage of all processes (including child processes) with PPID of 1. For a program like nginx/httpd which forks several child processes, ps/top gives the memory usage of each process separately. I want to know the total memory usage of nginx/apache instead of the individual child processes.

Joyce Babu
  • 424
  • 6
  • 19

2 Answers2

14

If you want something interactive, try :

atop - launch it and press 'm' (memory usage) and 'p' (group by process name).

If you want something scriptable, there's something a bit like the below - although it's not doing quite what you've asked for (PPID 1), but you can group based on e.g. process name using awk -

ps -eo pmem,vsize,cmd | grep -v '\[' | awk 'NR>2{mem[$3]+=$2}END {for(k in mem) print k " " mem[k]/1024000};' | sort -gk 2 | tail -n 10

There's probably some clever way to filter on ppid with the ps... but I'm too stupid to figure it out quickly.

David Goodwin
  • 271
  • 2
  • 5
1

On a distro using systemd, systemd-cgls should show memory usage per service. Doesn't always obtain the information though.

Cristian Ciupitu
  • 5,513
  • 2
  • 37
  • 47
u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • Thanks. The server is running CentOS 6, so there is no systemd. I have added the `centos-6` tag to the question. – Joyce Babu Jan 18 '15 at 05:51