The taskset
command is a utility on Linux systems that can be used to retrieve or set the CPU affinity of a process. CPU affinity refers to the ability of a process to run on specific CPUs or CPU cores.
To retrieve the CPU affinity of a process, use the taskset
command followed by the -p
option and the process ID:
taskset -p PID
For example:
taskset -p 12345
This will show the CPU affinity of the process with ID 12345
. The output will be a hexadecimal number representing the CPU mask, with each bit corresponding to a CPU or CPU core. For example, a mask of 0x00000003
indicates that the process is allowed to run on CPUs 0 and 1.
To set the CPU affinity of a process, use the taskset
command followed by the -p
option, the CPU mask, and the process ID:
taskset -p CPUMASK PID
For example:
taskset -p 0x00000003 12345
This will set the CPU affinity of the process with ID 12345
to CPUs 0 and 1.