Setting CPU affinity using taskset

Sayan picture Sayan · Jul 12, 2011 · Viewed 9.2k times · Source

I am using the taskset tool to set CPU affinity for one of my programs. How do I set the affinity on a single CPU only - since I was not sure about this, so I was doing this:

taskset -c 2-2 tests/prog 1 2 3

...expecting, that I am scheduling the program to run on CPU #2 only, following the similar way for other CPUs. Even if I'm right, this is a bad way to perform what I want IMO, can I get some help?

Thank you,
Sayan

Answer

user149341 picture user149341 · Jul 12, 2011

taskset -c 2 ... should work to pin the program to CPU #2 (which is the third CPU -- CPUs are numbered from 0).

Even if I'm right, this is a bad way to perform what I want IMO, can I get some help?

Depends on what you want. What are you trying to accomplish?