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.

  • 1
    I think you can find the answer to your question here. – 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 1:43
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.

|improve this answer|||||
  • Thanks Jim! Am I correct that this approach requires that the process exit before any information is available? (i.e. would this work for getting info on a daemon that never terminates?) – Travis Bear Jan 13 '15 at 20:06
  • Yes, it requires the [scriptname command or whatever ] to complete. – jim mcnamara Jan 13 '15 at 20:22
  • Added more information about long running process monitoring. – jim mcnamara Jan 13 '15 at 20:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.