哄骗低CPU使用率? [英] Trick to low CPU usage?

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

问题描述

嘿伙计们,


我正在编写一个连续运行的简单C ++应用程序。我正在从Cygwin的命令行运行来自XP的程序,并且它与Linux交叉兼容。

与Linux交叉兼容。

运行程序时,我注意到CPU使用率为100%,我的

应用程序窃取了97%。


I 我希望将其降低到最多10%的CPU使用率。什么是

技巧呢?


我注意到在某些应用程序上,比如那些用于解码视频的应用程序,你

可以指定使用多少CPU(高优先级,低优先级......),如何完成?b $ b?如何将我的应用程序CPU使用率降低到10%?


注意:我尝试运行睡眠(1),这使其低于10%,但是

告诉它睡一整秒是太多了。十分之一秒

就可以了,但睡眠只需要注意。然后我尝试使用clock()和

让它暂停,直到一段时间过去,比如.005的
秒,但是cpu坚持100%那个方法(因为它在

中运行,而循环测试时间通过了....即它不是真的

睡觉)。


提前感谢您的帮助!

Hey folks,

I''m writing a simple C++ application which runs continuously. I''m running
the program from the command line in Cygwin from XP, and it''s
cross-compatible with Linux.

While running the program, I notice that the CPU usage is 100%, with my
application stealing 97% of it.

I''d like to bring that down to at most 10% of the CPU usage. What''s the
trick to that?

I noticed that on certain applications like those used to decode video, you
can specify how much CPU to use (high priority, low priority...), how is
that accomplished? How can I bring my applications CPU usage down to 10%?

Note: I tried running sleep(1), and that brought it down below 10%, however
telling it to sleep for a full second is too much. A tenth of a second
would be fine, but sleep only takes ints. I then tried using clock() and
making it pause until a certain amount of time had passed like .005 of a
second, but the cpu sticks at 100% with that method (since it''s running in a
while loop testing the amount of time passed....i.e. it''s not really
sleeping).

Thanks in advance for the help!

推荐答案

" Eternally" < m@r.com>在消息中写道

news:ko ****************** @ twister.nyroc.rr.com
"Eternally" <m@r.com> wrote in message
news:ko******************@twister.nyroc.rr.com
嘿伙计们,

我正在编写一个连续运行的简单C ++应用程序。我是从XP的Cygwin命令行运行程序的,它与Linux交叉兼容。

在运行程序时,我注意到了我的应用程序窃取了97%的CPU使用率是100%。

我想将其降低到最多10%的CPU使用率。这是什么诀窍?

我注意到在某些应用程序(如用于解码视频的应用程序)上,您可以指定要使用多少CPU(高优先级,低优先级......),这是如何实现的?如何将我的
应用程序CPU使用率降低到10%?

注意:我试过运行睡眠(1),这使它降低到10%以下,然而告诉它睡了一整秒太多了。十分之一的时间没问题,但睡眠只需要注意。然后我尝试使用clock()并让它暂停直到一段时间的传递像.005秒一样,但cpu用这种方法保持100%(从那以后)它正在进行一段时间的循环测试
通过的时间....即它并没有真正睡觉。

提前感谢您的帮助!
Hey folks,

I''m writing a simple C++ application which runs continuously. I''m
running the program from the command line in Cygwin from XP, and it''s
cross-compatible with Linux.

While running the program, I notice that the CPU usage is 100%, with
my application stealing 97% of it.

I''d like to bring that down to at most 10% of the CPU usage. What''s
the trick to that?

I noticed that on certain applications like those used to decode
video, you can specify how much CPU to use (high priority, low
priority...), how is that accomplished? How can I bring my
applications CPU usage down to 10%?

Note: I tried running sleep(1), and that brought it down below 10%,
however telling it to sleep for a full second is too much. A tenth
of a second would be fine, but sleep only takes ints. I then tried
using clock() and making it pause until a certain amount of time had
passed like .005 of a second, but the cpu sticks at 100% with that
method (since it''s running in a while loop testing the amount of time
passed....i.e. it''s not really sleeping).

Thanks in advance for the help!



这是特定于平台的,在新闻组中更好地询问特定的

平台。我不知道Linux,但Windows下的Sleep(n)让你的

应用程序睡眠n毫秒(即n / 1000秒),而不是n

秒。

-

John Carson

1.要回复电子邮件地址,请删除donald

2不要回复电子邮件地址(在此处发帖)


This is platform specific and is better asked in newsgroups for the specific
platforms. I don''t know about Linux, but Sleep(n) under Windows puts your
application to sleep for n milliseconds (i.e., n/1000 seconds), not n
seconds.
--
John Carson
1. To reply to email address, remove donald
2. Don''t reply to email address (post here instead)




" John Carson" <做*********** @ datafast.net.au>在消息中写道

news:3f ******** @ usenet.per.paradox.net.au ...

"John Carson" <do***********@datafast.net.au> wrote in message
news:3f********@usenet.per.paradox.net.au...
" Eternally" < m@r.com>在消息中写道
新闻:ko ****************** @ twister.nyroc.rr.com
"Eternally" <m@r.com> wrote in message
news:ko******************@twister.nyroc.rr.com
嘿伙计们,
我正在编写一个连续运行的简单C ++应用程序。我是从XP的Cygwin命令行运行程序的,它与Linux交叉兼容。

在运行程序时,我注意到了我的应用程序窃取了97%的CPU使用率是100%。

我想将其降低到最多10%的CPU使用率。这是什么诀窍?

我注意到在某些应用程序(如用于解码视频的应用程序)上,您可以指定要使用多少CPU(高优先级,低优先级......),这是如何实现的?如何将我的
应用程序CPU使用率降低到10%?

注意:我试过运行睡眠(1),这使它降低到10%以下,然而告诉它睡了一整秒太多了。十分之一的时间没问题,但睡眠只需要注意。然后我尝试使用clock()并让它暂停直到一段时间的传递像.005秒一样,但cpu用这种方法保持100%(从那以后)它正在进行一段时间的循环测试
通过的时间....即它并没有真正睡觉。

提前感谢您的帮助!

这是特定于平台的,在新闻组中更好地询问
Hey folks,

I''m writing a simple C++ application which runs continuously. I''m
running the program from the command line in Cygwin from XP, and it''s
cross-compatible with Linux.

While running the program, I notice that the CPU usage is 100%, with
my application stealing 97% of it.

I''d like to bring that down to at most 10% of the CPU usage. What''s
the trick to that?

I noticed that on certain applications like those used to decode
video, you can specify how much CPU to use (high priority, low
priority...), how is that accomplished? How can I bring my
applications CPU usage down to 10%?

Note: I tried running sleep(1), and that brought it down below 10%,
however telling it to sleep for a full second is too much. A tenth
of a second would be fine, but sleep only takes ints. I then tried
using clock() and making it pause until a certain amount of time had
passed like .005 of a second, but the cpu sticks at 100% with that
method (since it''s running in a while loop testing the amount of time
passed....i.e. it''s not really sleeping).

Thanks in advance for the help!

This is platform specific and is better asked in newsgroups for the



特定平台。我不知道Linux,但是Windows下的Sleep(n)让你的
应用程序睡眠n毫秒(即n / 1000秒),而不是n
秒。


specific platforms. I don''t know about Linux, but Sleep(n) under Windows puts your
application to sleep for n milliseconds (i.e., n/1000 seconds), not n
seconds.




好​​吧,就像我说的那样,应用程序在某种程度上是跨平台的。我不是在寻找一个特定于平台的解决方案,因为它要么不会在Cygwin下运行Windows,也不会在Windows下运行。 Linux。


我或多或少都在寻找C ++解决方案。一个不存在吗?


哦,睡眠功能只需要一个表示秒的int,而不是
毫秒,所以这是行不通的。谢谢你的建议。



Well, like I said, the application is cross-platform to an extent. I''m not
looking for a platform specific solution, as then it either won''t run in
Windows under Cygwin, or it won''t run under Linux.

I''m more or less looking for a C++ solution. Does one not exist?

Oh, and the sleep function only takes an int representing seconds, not
milliseconds, so that doesn''t work. Thanks for the suggestion though.


永远写道:
嘿伙计们,

我写的很简单连续运行的C ++应用程序。我正在从Cygwin的命令行运行来自XP的程序,并且它与Linux交叉兼容。

在运行程序时,我注意到了CPU使用率是100%,我的
应用程序窃取了97%。

我想将其降低到最多10%的CPU使用率。这是什么诀窍?

我注意到在某些应用程序(如用于解码视频的应用程序)上,您可以指定使用多少CPU(高优先级,低优先级......),如何实现?如何将我的应用程序CPU使用率降低到10%?

注意:我尝试运行睡眠(1),并将其降低到10%以下,但是
告诉它睡觉整整一秒太多了。十分之一秒好了,但睡觉只需要注意。然后我尝试使用clock()和
让它暂停,直到一段时间过去,比如.005秒,但cpu用这种方法保持100%(因为它是'在
while循环中运行测试通过的时间量....即它不是真的睡觉了。

提前感谢您的帮助!
Hey folks,

I''m writing a simple C++ application which runs continuously. I''m running
the program from the command line in Cygwin from XP, and it''s
cross-compatible with Linux.

While running the program, I notice that the CPU usage is 100%, with my
application stealing 97% of it.

I''d like to bring that down to at most 10% of the CPU usage. What''s the
trick to that?

I noticed that on certain applications like those used to decode video, you
can specify how much CPU to use (high priority, low priority...), how is
that accomplished? How can I bring my applications CPU usage down to 10%?

Note: I tried running sleep(1), and that brought it down below 10%, however
telling it to sleep for a full second is too much. A tenth of a second
would be fine, but sleep only takes ints. I then tried using clock() and
making it pause until a certain amount of time had passed like .005 of a
second, but the cpu sticks at 100% with that method (since it''s running in a
while loop testing the amount of time passed....i.e. it''s not really
sleeping).

Thanks in advance for the help!



你在做什么需要97%的CPU?


您的代码事件是否被驱动?它可以是事件驱动的吗?


What are you doing that you need 97% of the CPU ?

Is your code event driven ? Can it be event driven ?


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

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