I want to calculate CPU time consumption of a particular process in system mode and user mode using statistics present in
There are two fields utime and stime in
/proc/<PID>/stat file, whose documentation says:
- utime: Amount of time that this process has been scheduled in user mode
- stime: Amount of time that this process has been scheduled in kernel(system) mode
I'm calculating CPU time consumption(in seconds) in system mode using following formula: (stime / No of clock ticks). For CPU time consumption in user mode I'm using the formula: (utime/ No of clock ticks)
I validated output of
atop command for system and user CPU time but my calculation is coming out wrong.
NOTE: Please let me know if I'm evaluating wrong fields for system and user CPU time for a process? Or what is the right way to calculate?
P.S I'm dividing these fields by No of Clock ticks in a second in order to calculate system CPU time and User CPU time in seconds as utime and stime are expressed in terms of CPU clock ticks.