Rohan
Rohan

Reputation: 383

Programmatically limit CPU usage by any application on Windows 7?

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

Upvotes: 7

Views: 26970

Answers (5)

Dirk Vollmar
Dirk Vollmar

Reputation: 176159

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.

Upvotes: 3

bradvido
bradvido

Reputation: 2871

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

Upvotes: 4

Ben Voigt
Ben Voigt

Reputation: 283624

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:

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.

Upvotes: 3

wojtek
wojtek

Reputation: 19

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!

Upvotes: 0

Aziz Kerimoglu
Aziz Kerimoglu

Reputation: 61

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.

Upvotes: 6

Related Questions