Programmatically limit CPU usage by any application on Windows 7?

半城伤御伤魂 提交于 2019-12-21 04:30:59

问题


I'm looking for a way to limit the CPU usage by any application on Windows 7 to 50%. I've tried searching the Internet for a way to do this, and it looks like this is an easy thing to do on Linux and Mac OS X (one command in the terminal) but I'm not sure how to do it on Windows 7. Any help would be much appreciated. Thanks!

Rohan


回答1:


You can use BES. It throttles CPU-hungry applications when asked. You can limit 3 programs maximum. I use this to run multiple online game clients and it works like a charm for me. You should run it with admin privilidges and in windows xp sp3 compatible mode. To adjust these settings, right click on the executable and chose options.

Here's the link for BES - CPU limiter.




回答2:


If you are on a multi-core processor, you can right click the process in the task manager and set the affinity. This will define which cores are allowed to run the process. Uncheck half of the cores and the process will use 50%.

Or see this to do it programagically: Set affinity with start /AFFINITY command on Windows 7




回答3:


You can't limit the CPU usage of a process on Windows 7 or earlier as this resource is managed by the OS*.

However, you can specify to run a process with a certain priority, e.g. to run below normal priority. The various scheduling priorities can be set using the SetPriorityClass API function.

Scheduling Priorities

What you are probably trying to prevent is that your process affects the performance of the system in a way that the user would notice. In that case, setting appropriate priorities will be a solution. After all, you got an expensive CPU so why not use it whenever you can?

* See @Ben Voigt's answer for a possible solution on Windows 8 and above.




回答4:


You can limit the CPU usage of your process or any other process by adding the process of interest to a Job object, and placing limits on the Job object.

One of the resource limits which can be configured for Job objects is CPU usage:

  • JOBOBJECT_BASIC_LIMIT_INFORMATION available since Windows XP and 2003
  • JOBOBJECT_CPU_RATE_CONTROL_INFORMATION new in Windows 8 and Server 2012.

If you have to use JOBOBJECT_BASIC_LIMIT_INFORMATION, pay careful attention to the note:

To register for notification when this limit is exceeded without terminating processes, use the SetInformationJobObject function with the JobObjectNotificationLimitInformation information class

And then use JOBOBJECT_END_OF_JOB_TIME_INFORMATION instead, since that's available pre-Windows 8.




回答5:


You can use an excellent program called "process lasso".

In lasso you can, for example, limit some specific program to 1 CPU and low priority. Every copy of that program will run with these settings. I have used this program to manage CPU on terminal server and it worked very well!



来源:https://stackoverflow.com/questions/2777137/programmatically-limit-cpu-usage-by-any-application-on-windows-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!