6

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

Sayan
  • 2,662
  • 10
  • 41
  • 56

2 Answers2

4

Easiest way would be using the CPU masks like

taskset -p mask pid

#taskset -p  0x00000001 11587
pid 11587's current affinity mask: ff
pid 11587's new affinity mask: 1
chandank
  • 953
  • 11
  • 24
3

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?

  • I was under the impression that taskset -c 2 would schedule the program on CPU#0, CPU#1 and CPU#2. Thank you for clarifying. I just want to run a program from a specific CPU at a time. BTW, was my syntax on the original question correct? – Sayan Jul 12 '11 at 03:01
  • 1
    Correct. `taskset -c 2-2` also works, it's just unnecessarily verbose. –  Jul 12 '11 at 05:47