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: