Linux – Is it possible to limit a Linux process so that it can only run on a particular core on a particular machine

central-processing-unitlinuxmulti-threadingunix

Let's say I have a quad-core box and four identical processes, each with ten threads. Is it possible, in Linux, to say that Process A is only allowed to run on CPU 0, Process B is only allowed to run on CPU 1, etc?

Best Answer

taskset <affinity mask> -p <process>

i.e.

taskset 1 -p 12345

to set process 12345 to use only processor/core 1

The bitmask can be a list (i.e. 1,3,4 to use cores 1 3 and 4 of a 4+ core system) or a bitmask in hex (0x0000000D the 1,3,4, 0x00000001 for just core 1)

taskset is usually in a package called shedutils.

Edit: almost forgot... If you want to set the affinity of a new command instead of change it for an existing process, use:

taskset <mask> <program> [<arg1>]...[<argN>]
Related Topic