CPU使用率 [英] CPU usage

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

问题描述

大家好!


我们正在使用

为Windows 95/98 / Me / NT4.0 / 2000 / XP / 2003开发一个应用程序Visual C ++ 6.0。我们需要将CPU使用率的百分比设置为应用程序进程。

是否有API来设置CPU使用率百分比?有人可以帮助我们吗?


提前致谢。

解决方案

Paulo Eduardo写道:

是否有用于设置CPU使用百分比的API?




No.

你想要什么?怎么样?


如果您的prcess有无限循环,那么将其删除并切换到

事件驱动的架构...


如果您的流程工作不重要,那么降低优先级。


请参阅:SetPriorityClass(...,BELOW_NORMAL_PRIORITY_CLASS)
http://msdn.microsoft.com/library/en ... orityclass.asp


-

问候

Jochen


我关于Win32和.NET的博客
http://blog.kalmbachnet。 de /


Jochen


实际上,如果我理解你,我们正在使用一个事件驱动的架构。

我们正在使用它的c函数和使用WMI服务的c ++方法。我们

也没有使用一个无限循环(for(;;))。我们的一些本地源代码是否需要访问固定驱动器(C:,E :)以获取其中的搜索文件(子目录

)。是否可以通过创建一个线程

控制进程的cpu使用来控制cpu使用?例如,如果进程使用的数据超过CPU的20%,那么''线程控制''会让进程保持1秒。


提前谢谢。


Jochen Kalmbach [MVP]"写道:

Paulo Eduardo写道:

是否有用于设置CPU使用率百分比的API?



没有。
你想做什么?

如果你的prcess有一个无限循环,然后删除它并转到
事件驱动的架构......

如果您的流程工作不重要,那么降低优先级。

请参阅:SetPriorityClass(...,BELOW_NORMAL_PRIORITY_CLASS)
http://msdn.microsoft.com/library/en .. .orityclass.asp

-
问候
Jochen

关于Win32和.NET的博客
http://blog.kalmbachnet.de/



Hi Paulo!

实际上,如果我理解你,我们正在使用事件-d我们正在使用其中使用WMI服务的c函数和c ++方法。我们没有使用一个无限循环(for(;;))。我们需要一些本地源代码来访问其中的搜索文件的固定驱动器(C:,E :)(子目录也是如此)。是否可以通过创建一个控制进程的cpu使用的线程来控制cpu的使用?例如,如果进程使用的内容比CPU的20%多,那么''线程控制''将进程暂停1秒。




为什么你想限制你的CPU使用率?为什么不降低优先级?


要获得进程/线程时间,可以使用


请参阅:GetProcessTimes
< a rel =nofollowhref =http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getprocesstimes.asp\"target =_ blank> http: //msdn.microsoft.com/library/de...ocesstimes.asp




请参阅:GetThreadTimes
http://msdn.microsoft .com / library / en ... ocesstimes.asp

你应该知道,分辨率大约是10-15毫秒......


为了正确实现它你还需要知道(逻辑)

处理器的数量......


参见:GetSystemInfo
http:// msdn。 microsoft.com/library/en...systeminfo.asp


-

问候

Jochen


关于Win32和.NET的博客
http://blog.kalmbachnet.de/


Hi, All!

We are developing one app for windows 95/98/Me/NT4.0/2000/XP/2003 using
Visual C++ 6.0. We need to set the % of CPU Usage to app process. Is there
an API to set % of CPU Usage? Can Someone help us?

Thanks in advance.

解决方案

Paulo Eduardo wrote:

Is there an API to set % of CPU Usage?



No.
What are you trying to do?

If your prcess has an endless-loop, then remove it and switch to
event-driven architecture...

If the work of your process is not important, then reduce the priority.

See: SetPriorityClass(..., BELOW_NORMAL_PRIORITY_CLASS)
http://msdn.microsoft.com/library/en...orityclass.asp

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/


Hi, Jochen

Actually, if I understood you, we are using an event-driven architecture,.
We are using in it c functions and c++ methods that use WMI service. We are
not using one endless loop (for (;;)) too. Is some local of source code we
need to access fixed drives (C:,E:) for search files in them (subdirectories
too). Is it possible to control the cpu usage by process creating one thread
that control the cpu usage of process? For example, If process is using more
than 20% of CPU, the ''thread control'' sleep the process for 1s.

Thanks in advance.

"Jochen Kalmbach [MVP]" wrote:

Paulo Eduardo wrote:

Is there an API to set % of CPU Usage?



No.
What are you trying to do?

If your prcess has an endless-loop, then remove it and switch to
event-driven architecture...

If the work of your process is not important, then reduce the priority.

See: SetPriorityClass(..., BELOW_NORMAL_PRIORITY_CLASS)
http://msdn.microsoft.com/library/en...orityclass.asp

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/



Hi Paulo!

Actually, if I understood you, we are using an event-driven architecture,.
We are using in it c functions and c++ methods that use WMI service. We are
not using one endless loop (for (;;)) too. Is some local of source code we
need to access fixed drives (C:,E:) for search files in them (subdirectories
too). Is it possible to control the cpu usage by process creating one thread
that control the cpu usage of process? For example, If process is using more
than 20% of CPU, the ''thread control'' sleep the process for 1s.



Why do you want to limit your CPU usage? Why not just lower your priority?

To get the process/thread-times you can use

See: GetProcessTimes
http://msdn.microsoft.com/library/de...ocesstimes.asp

or

See: GetThreadTimes
http://msdn.microsoft.com/library/en...ocesstimes.asp

You should be aware, that the resolution is about than 10-15 ms...

To implement it correctly you also need to know the number of (logical)
processors...

See: GetSystemInfo
http://msdn.microsoft.com/library/en...systeminfo.asp

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/


这篇关于CPU使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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