Setting CPU affinity using taskset
Asked Answered
B

2

7

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

Bane answered 12/7, 2011 at 2:41 Comment(0)
L
2

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?

Lengthen answered 12/7, 2011 at 2:52 Comment(2)
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?Bane
Correct. taskset -c 2-2 also works, it's just unnecessarily verbose.Lengthen
L
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
Lastly answered 14/8, 2013 at 15:51 Comment(0)
L
2

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?

Lengthen answered 12/7, 2011 at 2:52 Comment(2)
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?Bane
Correct. taskset -c 2-2 also works, it's just unnecessarily verbose.Lengthen

© 2022 - 2024 — McMap. All rights reserved.