3

I have the following code in a bash script:

echo "bash pid => $$";
echo "processor affinity before => $(taskset -p $$)"
taskset -cp ${AN_INTEGER} $$
echo "processor affinity after => $(taskset -p $$)"

I get this output:

processor affinity before => pid 5047's current affinity mask: ff
pid 5047's current affinity list: 0-7
pid 5047's new affinity list: 1
processor affinity after => pid 5047's current affinity mask: 2

does anyone know what this means?

The reason I started messing with processor affinity is because I would launch multiple bash child processes, and all the bash child process affinities had the value "ff" so it seemed like they were all targeting the same CPU.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Alexander Mills
  • 9,330
  • 19
  • 95
  • 180

1 Answers1

5

taskset uses a mask to specify which CPUs a process can run on. Each bit maps to one CPU; if a bit is set to 1, the process can run on that CPU, if it’s set to 0, it can’t. Thus a mask of FF means any CPU from 0 to 7 (not one specific CPU), and a mask of 2 means only CPU 1.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164