I have a commandline program that launches a bunch of subprocesses (which themselves can launch more subprocesses). I'd like to somehow determine the peak combined memory usage of all subprocesses in the whole tree. This is on linux; I don't have source code for the program.
I can run the program from python with subprocess.call(), and I can get the max resident set size with resource.getrusage(RUSAGE_CHILDREN).ru_maxrss. I think that only returns the value for the program itself, but not its children. What is the equivalent of getrusage() that applies to the whole process tree recursively?
P.S. man getrusage says this:
For RUSAGE_CHILDREN, this is the resident set size of the largest child, not the maximum resident set size of the process tree.
So it's not the peak of the first child as I thought, but also not the instantaneous peak of the process tree or the sum of peaks of the children.