How do you limit a process' CPU usage on Windows? (need code, not an app)

前端 未结 3 1349
离开以前
离开以前 2021-02-09 16:06

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

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-09 16:41

    CPU usage is fairly simple to estimate using QueryProcessCycleTime. The machine's processor speed can be obtained from HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\\~MHz (where is the processor number, one entry for each processor present). With these values, you can estimate your process' CPU usage and yield the CPU as necessary using Sleep() to keep your usage in bounds.

提交回复
热议问题