Set Process Affinity of System process to reserve core for own Application

冷暖自知 提交于 2019-12-22 17:48:40

问题


I am working with a CPU-intensive real time application, and therefore I am trying to reserve a whole core for it.

To accomplish this in Windows, I am trying to set the CPU affinity of all running processes to the other cores, and then set the affinity of my real time application to the "free" core. Additionally, I am setting the priority to high.

Unfortunately, the following code (129 for testing as it means first and last core on my system) is not changing the affinity of all running processes:

while (Process32Next(hSnapShot, processInfo)!=FALSE)
{
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, processInfo->th32ProcessID);
    SetProcessAffinityMask(hProcess, 129);
}

Some system processes, like svchost.exe or csrss.exe, have the affinity 0xCCCCCCCC (looks like it is not initialized and is not used at all). And, of course, they are keeping it after a failed SetProcessAffinityMask().

Also, using Task Manager is not possible, as it denies access when trying to change affinity of those system processes.

Is it possible to change affinity for those processes as well?

Additional Information:

  • Windows 7 64bit
  • Real-time app has only one thread, therefore one core is "enough".
  • The below images show the difference:

Not working:

Working:

来源:https://stackoverflow.com/questions/40453645/set-process-affinity-of-system-process-to-reserve-core-for-own-application

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