Processor affinity on Linux using taskset

1.2k Views Asked by At

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.

1

There are 1 best solutions below

1
On

The affinity mask controls the set of processors that a process may run on - not a single specific processor. Bits that are a 1 in this mask mean represent a processor that the process can run on. Since you specified that you want this process run on only CPU 1, the affinity mask is now 0b00000010, or 2.