supervisord is running on CentOS server. If I do

ps -e -o %mem,%cpu,cmd | grep supervisord | awk '{memory+=$1;cpu+=$2} END {print memory,cpu}'

I get 0 0 just because supervisord is just an initialization daemon. It runs four child processes on my server:

# pgrep -P $(pgrep supervisord) | wc -l

How can I find summarized CPU and memory usage of these child processes in one-line-command?

3 Answers 3


The code from happyraul's answer,

pgrep -P $(pgrep supervisord) | xargs ps -o %mem,%cpu,cmd -p | awk '{memory+=$1;cpu+=$2} END {print memory,cpu}'

will get only one child layer.

If you want to search for all processes that were derived from a main pid, use this code:

ps -o pid,ppid,pgid,comm,%cpu,%mem  -u {user name} | {grep PID_PRINCIPAL}

The pid of main process is the PGID of child processes.


Given a pid,

pstree -p $pid | grep -o '([0-9]\+)' | grep -o '[0-9]\+' |\
  xargs ps -o %mem,%cpu,cmd -p | awk '{memory+=$1;cpu+=$2} END {print memory,cpu}'
# 15.5 905.2

I had no luck getting the pids of all child processes from pgrep.

  • 3
    %cpu in ps is, in fact, problematic. It is calculated as CPU time used divided by the time the process has been running - that is, historical average of the %CPU usage, not its current value.
    – VladV
    Oct 14, 2016 at 12:29

Try using xargs:

pgrep -P $(pgrep supervisord) | xargs ps -o %mem,%cpu,cmd -p | awk '{memory+=$1;cpu+=$2} END {print memory,cpu}'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .