How to bind a certain process to specified core?

Taskset is used to set or retrieve the CPU affinity of a running process given its PID or to launch a new COMMAND with a given CPU affinity. Under latest version of Debian / Ubuntu / Redhat Linux taskset is installed by default with util-linux package.

The CPU affinity is represented as bitmask, with the lowest order bit corresponding to the first logical CPU and the highest order bit corresponding to the last logical CPU. For example:

* 0x00000001 is processor (1st processor)
* 0x00000003 is processors and #1
* 0x00000004 is processors (3rd processor)

To set the processor affinity of process 13545 to processor (1st processor) type following command:

# taskset 0x00000001 -p 13545
If you find a bitmask hard to use, then you can specify a numerical list of processors instead of a bitmask using -c flag:
# taskset -c 1 -p 13545
# taskset -c 3,4 -p 13545

Where,
* -p : Operate on an existing PID and not launch a new task (default is to launch a new task)

Share Button

Leave a comment

Your email address will not be published. Required fields are marked *