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:

* 0×00000001 is processor (1st processor)
* 0×00000003 is processors and #1
* 0×00000004 is processors (3rd processor)

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

# taskset 0×00000001 -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)

Related posts:

  1. How can I set real time priority for a process
  2. Print I/O operations per-process by iopp
  3. Simple ways to check Process running time
Tags: , ,


Joseph chen is a system administrator from south China. He has a keen interest in Open Source and system administration solutions.

Leave a Reply

© 2006-2009 Admon Home. All rights reserved.