This question has answers for Windows OS. However I am looking for something similar for my OS X (or any *nix) machine.
I want to track CPU usage of a process and all the child it spawns, over the period of time, so that I can plot a graph. Following gives me CPU usage of the single process :
while :;do ps -p $PID -o %cpu=;sleep 0.5;done
But it doesn't give me usage of it's children. One way I could think of is using a python script. first I will run following :
pgrep -P $PID
This will give me a list of child processes. Now I will spawn a child process (using python subprocess module) for each of these child process and also one for one parent which will run the first command.
But is there any simpler/better way to do this?
Also above will not give me consolidated CPU usage of parent and it's children. I really don't care how much each child is using. All I want is CPU usage percentage of that process and it's children.