2

This might be an obvious thing, but I can't seem to figure out how to do it.

Assuming that I spawn a process like this:

    popen = subprocess.Popen(args, executable=executable,
                                  bufsize=-1,
                                  stdin=subprocess.PIPE,
                                  stdout=subprocess.PIPE,
                                  close_fds=True,
                                  env={})
    popen.wait()

Is there any way I can measure the cpu usage of this child, but not the grandchildren?

   resource.getrusage(resource.RUSAGE_CHILDREN)

Gives me all children and granchildren.

pehrs
  • 1,481
  • 2
  • 15
  • 21

1 Answers1

2

You can use psutil

import psutil
popen = ...
p = psutil.Process(popen.pid)
print p.get_cpu_times()
Mihai Stan
  • 1,052
  • 6
  • 7