0

Get total %cpu,%mem for a process including all threads or sub processes?

For example rsync if you do the following, you get the %cpu,%mem for the parent process only. Where 9215 is pid of active rsync.

ps -p 9215 -o %cpu,%mem

How can one get the entire, total %cpu,%mem for the entire rsync process including its threads or sub processes?

Schorschi
  • 3
  • 1

1 Answers1

0

On Linux, you can isolate a command to a cgroup and get its total resource use, even if it execs other processes.

For one-off commands on systemd systems, create a transient unit: systemd-run --unit=run rsync-script.sh where "run" is some descriptive name and "rsync-script.sh" is a script doing the thing. See resources by cgroup in systemd-cgtop. Actually getting numbers requires enabling resource accounting by default, see man systemd.resource-control


Threads are the simple case that doesn't require fancy accounting to get. Processes report the CPU and private memory total of all their threads. Have a look at multiple threaded task groups with pidstat -t

John Mahowald
  • 32,050
  • 2
  • 19
  • 34