Is there a way to tell the OS to run a process/thread on a separate core? To keep that process isolated?
Like using pthreads or fork() in C?
Is there a different way to do it in Linux vs Windows?
If you want to ensure that the processes/threads run on a separate CPU core, then
SetProcessAffinityMask and SetThreadAffinityMask, andsched_setaffinity if not using pthreads, and if using pthreads, you should use pthread_setaffinity_np instead.The function fork is not useful for this, as the purpose of this function is to split one process into two different processes, which is something completely different. The function fork will make no attempt to ensure that these two processes will run on separate cores. Which core which process runs on is entirely up to the scheduler of the kernel, unless you set an affinity mask as described above.
In your question, your stated goal is to keep the processes "isolated". It is worth noting that even two processes running on the same core will be isolated from each other, because their virtual address spaces will be separate. Whenever a CPU core switches to running a different process, the two virtual address spaces will be swapped as part of the context switch. Therefore, two processes running on the same core will only interfere with each other with regards to performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With