Problem of calculate the cpu usage

view full story

https://bbs.archlinux.org – When I try to calculate the cpu usage by parse out the data from /proc/<PID>/stat, I meet a problem.Firstly ,for each process I calculate the cpu usage % with below manner:prb_time = utime+stime; the utime and stime is from the file /proc/<PID>/stat. After 2 seconds calculate the prb_time again. And then get the real run time of the process in the two second by the below:prb_real_run_time = prb_time_new - prb_time_old. I calculate all the processes under /proc and sum them. Let's name the summing result is sum_result_prb_time.Secondly, I parse out the data from the first line( (HowTos)