How to set CPU affinity using taskset

taskset is a tool that can be used to get and set the CPU affinity of a running process. This can be useful to find out which of the cores or CPUs of your system has been assigned to a given process by the Linux scheduler. You can use this tool to change, increase or decrease the cores assigned to a process.

  • To find out CPU affinity of a process using its PID:
$ taskset -p 25694
pid 25694's current affinity list: 0,1
  • To restrict the above process to core 3 of my computer:
$ taskset -c -p 2 25694
pid 25694's current affinity list: 0,1
pid 25694's new affinity list: 2
  • To give the last 4 cores of my 8-core CPU to the above process:
$ taskset -c -p 4-7 25694
pid 25694's current affinity list: 0,1
pid 25694's new affinity list: 4,5,6,7

Tried with: Util-Linux 2.26.2 and Ubuntu 15.10

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s