问题描述
如何,我可以得到进程的CPU使用率在C ??
How can i Get process Cpu usage in c??
我需要evrey进程和线程的CPU使用情况。
I need Cpu usage of evrey process and threads.
请给我一个例子。
谢谢!
推荐答案
在普通的C,这是不可能的,但由于问题也标记视窗:
In plain C, this is not possible, but since the question is also tagged "Windows":
CPU占用CPU时间的实时分配。该并功能给你的信息(其它功能,如性能计数器,这约阿希姆Pileborg上述之一,但我认为这个人是可能更容易)。
CPU usage is CPU time divided by real time. The GetThreadTimes and GetProcessTimes functions give you that information (among other features such as performance counters, which Joachim Pileborg mentioned above, but I think this one is probably easier).
您可能还需要使用的首先要知道什么是进程和线程存在的。你需要线程/进程的ID转换为把手,但我想这不会是一个很大的障碍(即调用OpenProcess
)。
You probably also want to use CreateToolhelp32Snapshot first to know what processes and threads exist at all. You'll need to translate thread/process IDs to handles, but I guess that won't be a big hurdle (i.e. OpenProcess
).
这篇关于获取进程的CPU使用率在C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!