title: Set Process Affinity of System process to reserve core for own Application
body: <p>I am working with a CPU-intensive real time application, and therefore I am trying to reserve a whole core for it.</p>
  
  <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>while (Process32Next(hSnapShot, processInfo)!=FALSE)
  {
      hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, processInfo-&gt;th32ProcessID);
      SetProcessAffinityMask(hProcess, 129);
  }
  </code></pre>
  
  <p>Some system processes, like <code>svchost.exe</code> or <code>csrss.exe</code>, have the affinity <code>0xCCCCCCCC</code> (looks like it is not initialized and is not used at all). And, of course, they are keeping it after a failed <code>SetProcessAffinityMask()</code>.</p>
  
  <p>Also, using Task Manager is not possible, as it denies access when trying to change affinity of those system processes.</p>
  
  <p>Is it possible to change affinity for those processes as well?</p>
  
  <p>Additional Information:</p>
  
  <ul>
  <li>Windows 7 64bit</li>
  <li>Real-time app has only one thread, therefore one core is "enough".</li>
  <li>The below images show the difference:</li>
  </ul>
  
  <p>Not working:</p>
  
  <p><a href="https://i.stack.imgur.com/LcoSj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LcoSj.png" alt="Not working"></a></p>
  
  <p>Working:</p>
  
  <p><a href="https://i.stack.imgur.com/ljOnb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ljOnb.png" alt="Working"></a></p>