You are not logged in.

#1 2011-02-26 14:29:49

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

[SOLVED] the time spend by a process and all of its subprocesses

Is there a way to have the CPU time spend by a processes and all the subprocesses it has spawned? Something like the time command but I want also the CPU time spent in the subprocesses that the main process has spawned. Some programs launches several subprocesses, in this cases just have the USER field of the time command is not very relevant. This is especially true for bash scripts but I see that some browsers also launch several subprocesses.

Last edited by olive (2011-02-26 19:27:09)

Offline

#2 2011-02-26 15:06:36

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [SOLVED] the time spend by a process and all of its subprocesses

function child_search() {
  ps --pid $1 -o bsdtime=
  for pid in $(ps --ppid $1 -o pid=); do
    child_search $pid
  done
}

child_search $(pgrep firefox) | awk -F: '{minutes+=$1; seconds+=$2} END {print minutes ":" seconds}'

I don't know how/if this makes sense with threads though.

Offline

#3 2011-02-26 19:23:47

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: [SOLVED] the time spend by a process and all of its subprocesses

Thanks!

Offline

Board footer

Powered by FluxBB