Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7557495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:08:48+00:00 2026-05-30T12:08:48+00:00

There is programs that is able to limit the CPU usage of processes in

  • 0

There is programs that is able to limit the CPU usage of processes in Windows. For example BES and ThreadMaster. I need to write my own program that does the same thing as these programs but with different configuration capabilities. Does anybody know how the CPU throttling of a process is done (code)? I’m not talking about setting the priority of a process, but rather how to limit it’s CPU usage to for example 15% even if there is no other processes competing for CPU time.

Update: I need to be able to throttle any processes that is already running and that I have no source code access to.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:08:49+00:00Added an answer on May 30, 2026 at 12:08 pm

    Very simplified, it could work somehow like this:

    1. Create a periodic waitable timer with some reasonable small wait time (maybe 100ms). Get a “last” value for each relevant process by calling GetProcessTimes once.
    2. Loop forever, blocking on the timer.
    3. Each time you wake up:
      • if GetProcessAffinityMask returns 0, call SetProcessAffinityMask(old_value). This means we’ve suspended that process in our last iteration, we’re now giving it a chance to run again.
      • else call GetProcessTimes to get the “current” value
      • call GetSystemTimeAsFileTime
      • calculate delta by subtracting last from current
      • cpu_usage = (deltaKernelTime + deltaUserTime) / (deltaTime)
      • if that’s more than you want call old_value = GetProcessAffinityMask followed by SetProcessAffinityMask(0) which will take the process offline.

    This is basically a very primitive version of the scheduler that runs in the kernel, implemented in userland. It puts a process “to sleep” for a small amount of time if it has used more CPU time than what you deem right. A more sophisticated measurement maybe going over a second or 5 seconds would be possible (and probably desirable).

    You might be tempted to suspend all threads in the process instead. However, it is important not to fiddle with priorities and not to use SuspendThread unless you know exactly what a program is doing, as this can easily lead to deadlocks and other nasty side effects. Think for example of suspending a thread holding a critical section while another thread is still running and trying to acquire the same object. Or imagine your process gets swapped out in the middle of suspending a dozen threads, leaving half of them running and the other half dead.

    Setting the affinity mask to zero on the other hand simply means that from now on no single thread in the process gets any more time slices on any processor. Resetting the affinity gives — atomically, at the same time — all threads the possibility to run again.

    Unluckily, SetProcessAffinityMask does not return the old mask as SetThreadAffinityMask does, at least according to the documentation. Therefore an extra Get... call is necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any programs that will allow you to follow a sql transaction through
Just a curious question but is there any programs that can help/aid you when
There are a lot of programs, Visual Studio for instance, that can detect when
Does there exist a free Windows software program that will help you generate regular
Is there any Visual Studio add-on (or windows/unix stand-alone program) that creates stub implementations
I have some native (as in /SUBSYSTEM:NATIVE ) Windows programs that I'd like to
Is there a limit to the rows that IEnumerable.Count() (or IQueryable.Count()) using LINQ to
There appears to be a somewhat standard descript.ion file in Windows programs universe which
Is there an OS or user-account level modification for windows 7 that I can
Is there a program that will print a nicely formatted tree from XML data?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.