# CPU utilization for a process in userspace and kernel space



## Avinash K (Jan 10, 2019)

How could I get per process CPU time consumed by this process in kernel mode and CPU time consumed by this process in user mode , top and ps output doesnt seem to show the breakup data


----------



## ralphbsz (Jan 11, 2019)

Try `/usr/bin/time foo` to get that for the command "foo".  You can also use the various built-in "time" commands from various shells; I like to use the standardized `/usr/bin/time` instead, so I always get the same output.

You can also keep track of this from within a running program.  For example in python, the os.times() function returns it (see the documentation).  There are ways to do this in other languages too, and I'm too lazy this evening to look them up.  Google is your friend.


----------



## Bobi B. (Jan 11, 2019)

Try procstat(1): `procstat -r <pid>` for someone else's process, or getrusage(2) if you want to read your process' resource utilization (from C).


----------

