Is it possible to limit a Linux process so that it can only run on a particular core on a particular machine?
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>]
taskset (util-linux 2.13-pre7) usage: taskset [options] [mask | cpu-list] [pid | cmd [args...]] set or get the affinity of a process
-p, --pid operate on existing given pid -c, --cpu-list display and specify cpus in list format -h, --help display this help -v, --version output version information
The default behavior is to run a new command: taskset 03 sshd -b 1024 You can retrieve the mask of an existing task: taskset -p 700 Or set it: taskset -p 03 700 List format uses a comma-separated list instead of a mask: taskset -pc 0,3,7-11 700 Ranges in list format can take a stride argument: e.g. 0-31:2 is equivalent to mask 0x55555555
you can alway optimize you server as u r need