获取进程的CPU使用率在C [英] GET Process Cpu Usage In c

查看:296
本文介绍了获取进程的CPU使用率在C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何,我可以得到进程的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时间的实时分配。该 GetThreadTimes GetProcessTimes 功能给你的信息(其它功能,如性能计数器,这约阿希姆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).

您可能还需要使用的 CreateToolhelp32Snapshot 首先要知道什么是进程和线程存在的。你需要线程/进程的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆