I'm working on a program that shows the percentage of every process running on a machine with Linux. The problem is that the percentage I get often differs from the one displayed by the top command.
I searched for many hours on the web but what I find is almost always the same formula
100 * (stime + utime)/ (totalCPUTime - processStartTime).
I get the totalCPUTime summing the 7 CPU values in /proc/stat , while stime, utime and processStartTime are values taken form /proc/<pid>/stat.
Am I doing something wrong?
Does the fact that I am running the program on a multicore machine affect somehow the result?
Does somone know how the top calculates this value?
Thank you