Is there a function in Linux which allows me to see how much CPU did a process use after it finished? I need something similar to bash “time” command. I am fork()ing the process and then waiting using wait() for a child to finish. The way of accurately measuring “real” time (actual time elapsed between fork() and exit()), even when wait() was called a long after the child process became zombie is also welcome, but I’m not sure if its possible.
Share
Sure,
wait3andwait4have you covered. Alternatively (and more portably) you could usegetrusage(2).Example:
wait3Example:
getrusageOf course,
wait3andwait4are just a convenience. So you could usegetrusage:The disadvantage is that this tells you the resources used by ALL the terminated children.
So, once you get it, what do you do with
rusage?struct rusagehas the following form: