Quick Linux Tip #75:
Question: My high-priority process needs dedicated cores. How do I pin it to specific CPUs?
Try: taskset -cp 0,1 3456
Info: taskset sets or retrieves CPU affinity. The -c option specifies CPU numbers, while -p applies the affinity to an existing process by PID.
Examples:
- $
taskset -c 0-3 ./program# Launch a program on CPUs 0-3 - $
taskset -c 4,5,6,7 -p 3456# Reassign PID 3456 to CPUs 4-7 - $
numactl --cpunodebind=0 ./program# Bind a process to NUMA node 0
Note: CPU affinity limits a process to the selected CPUs, but does not by itself make those CPUs exclusively available to that process. For stronger CPU isolation, combine affinity with appropriate kernel CPU-isolation features such as isolcpus. Use numactl when CPU and memory locality across NUMA nodes matters.
Leave a Reply