-1

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

4

1 回答 1

1

如果您想知道 top 是什么,您应该查看源代码:)

top.c cvs 存储库

procps 主页

于 2013-06-01T11:54:13.547 回答