2

If I have a process that spawns child processes, is there a good way to get a single number representing the combined CPU use of that process and its children? i.e is there a simple shell command available, or perhaps some info in /proc?

Target OS is either Centos or Ubuntu.

Travis Bear
  • 123
  • 1
  • 4
  • 1
    I think you can find the answer to your question [here](http://stackoverflow.com/a/12871375/1742825). – Ramesh Jan 12 '15 at 21:52
  • @Ramesh This answer includes a caveat that the parent process be "waiting for" the child processes. What does this mean, that the parent has to block until children complete? (i.e. it cannot work with child processes that are forked to run in the background?) – Travis Bear Jan 13 '15 at 01:43

1 Answers1

1

Run a process this way:

time scriptname  # or
time command 

It will report the sum of children plus parent

As soon as you add the word daemon, the picture changes. top will show the approximate value, top -p [pid] You can also read /proc[pid]/stat.utime and friends (utime, stime, cutime, cstime (children start with c) ) with C or perl or python. Generally, once you get used to this data, you may discover that system time and user time become as important as total cpu time for performance evaluation.

ps -p [pid] -o %cpu is not very informative - it just shows current amounts of cpu being used, not accumulated time.

jim mcnamara
  • 745
  • 4
  • 8