I wish to pin a process to a CPU1 in my dual CPU machine - how can I do it in Linux - any pointers ?
-
1The usual response to questions like this is why? The OS generally knows better than you! (Thought I'd ask this question cos someone will!)– Jon EgertonCommented Mar 24, 2011 at 12:41
-
You can use processor affinity (install schedutils) and use taskset -c 1 -p <PID>. But since you have only 2 processors until and unless you have very strong reasons avoid it.– ZimbabaoCommented Mar 24, 2011 at 12:50
2 Answers
You should think long and hard about why you think you're smarter than the scheduler. After that, if you still want to set the cpu affinity of a process on linux you can use the taskset command or, if you're writing the program yourself, the sched_setaffinity system call.
-
1For example, it is essentially always wrong to migrate a compute-bound process with intensive cache re-use.– mabrahamCommented May 28, 2014 at 16:11
Fwiw: we did this, pinning every process in an averagely complex application that we well mastered. We found out that the linux kernel scheduler is better than us at allowing processors and processing time, as others stated above ...