Bind A Process To Specific Cores

In a multi CPU or multi thread enviroment any process or program that utilizes all of them can have the potential of bogging down your system. Linux easily gives you the option to bind* a program to specifc cores leaving your operating system or other processes to use the remaining cores. This can have give you a performance boost for cpu intensive applications without restricting normal OS activities.

How Many Cores Do You Have

If you already know how many cores you have great....if your dont run the command cat /proc/cpuinfo | grep processor. This will output all the processors and cores you have available to you. Each line outputed is a core. If you have 4 lines of output then you have 4 cores. You can also use the command lscpu | grep "CPU(s):" to find out the listing of cpu's


Finding The Process ID

First you need to find out the process ID of the program you wish to restrict. This can easily be accomplished using the top or ps aux commands.


Bind The Process To Specific Cores

Now use the taskset command to modify the core bindings. If you had a process ID of 4567 and you wanted to let it use the first 3 cores of a 4 core system. Use the command taskset -pac 0,1,2 4567


taskset is the program to bind the process, -pac is the options we need to pass it, then comes the core listings (cpu's are numbered 0,1,2,3,4,5 etc etc so your first core is 0), then the final parameter is the process id.


If you only have a 2 core system and wanted the process to use the second core only you could use the command taskset -pac 1 4567.