Although the kernel does handle assigning cores to processes, CPU affinity can be viewed and manually set for a process using taskset
- see man taskset
. However, it should be said that this is only used in very particular circumstances, and in an instance when, perhaps for a benchmarking or troubleshooting task, one wants to run one process in one particular core. One can find the pid of a process with ps -oe pid,args
then query taskset for that affinity: taskset -p <pid>
, which will return something like pid 2027's current affinity mask: 1
.
To find the number of processing units available, use nproc
- see man nproc
. If you need to run an old app or game on a single core you can launch it with taskset -c <core> <app>
. (Cores begin at 0). Other programs such as xargs can be made to run with parallel execution units using the P switch followed by n (number required)- see man xargs
.