0

I read through the docs for cat /proc/pid/stat It displays many numbers. The process I am calculating this for is running in an infinite loop. So the values will keep on changing. I see that there is something called utime and stime
I am not sure if these give the exact user time and kernel time for the running process?
Also is there a way to just extract these two numbers from the output rather than manually determining which number corresponds to utime and stime?

1 Answer 1

0

Yes, those fields give the exact user time and kernel time for the running process; man 5 proc describes them as

Amount of time that this process has been scheduled in user mode, measured in clock ticks (divide by sysconf(_SC_CLK_TCK)). This includes guest time, guest_time (time spent running a virtual CPU, see below), so that applications that are not aware of the guest time field do not lose that time from their calculations.

and

Amount of time that this process has been scheduled in kernel mode, measured in clock ticks (divide by sysconf(_SC_CLK_TCK)).

respectively. (Guest time is field 43.)

You can extract them with any field-based tool, e.g.

awk '{print $14, $15}' /proc/$$/stat

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .