I wish to pin a process to a CPU1 in my dual CPU machine - how can I do it in Linux - any pointers ?

  • 1
    The 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 Egerton Mar 24 '11 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. – Zimbabao Mar 24 '11 at 12:50

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.

  • 1
    For example, it is essentially always wrong to migrate a compute-bound process with intensive cache re-use. – mabraham May 28 '14 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 ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.