taskset Cheatsheet - CPU Affinity

All essential taskset commands organized by use case, with 37+ entries you can copy and run directly. Find the right command fast when you need it.

SysOps·37 commands·Last updated 2026-07-21
Back to SysOps

Basic Usage 6

taskset -p <pid>
Show a process's CPU affinity mask
taskset -c -p <pid>
Show affinity in CPU-list format
taskset -c 0,1 <command>
Pin to CPUs 0 and 1 on launch
taskset -c 0-3 <command>
Pin to CPUs 0-3 on launch
taskset -p <mask> <pid>
Change a running process's CPU mask
taskset -cp 0,1 <pid>
Repin a running process to CPUs 0,1

CPU Mask & List Format 7

0x00000001
Hex mask: CPU 0
0x00000003
Hex mask: CPUs 0 and 1
0x0000000f
Hex mask: CPUs 0-3
-c 0
CPU-list format, more readable
-c 0,2,4
Specify discrete CPUs
-c 0-3,8-11
Mixed range list
taskset -c 0xff <command>
Bind to CPUs 0-7 with a hex mask

Pin Running Processes 4

taskset -cp 0 $(pgrep nginx)
Change the nginx master's affinity
for p in $(pgrep -f app); do taskset -cp 0-3 $p; done
Batch-repin matching processes
taskset -cp 0-3 <pid>
Bind a PID to CPUs 0-3
taskset -ap 0-1 <pid>
Set affinity for the process and all its threads

Affinity & System Info 5

cat /proc/<pid>/status | grep Cpus_allowed
View a process's CPU mask
cat /sys/devices/system/cpu/online
View online CPU numbers
nproc
View the number of available CPU cores
lscpu
View CPU architecture details (cores, cache, NUMA)
lscpu | grep NUMA
View NUMA node information

NUMA Optimization 5

numactl --hardware
View NUMA topology and node layout
numactl -c 0 -m 0 ./app
Bind CPU and memory to NUMA node 0
numactl --cpunodebind=0 --membind=0 ./app
Full NUMA binding (CPU + memory)
numastat -p <pid>
View a process's memory distribution per NUMA node
numactl --interleave=all ./app
Interleave memory across all nodes

Practical Scenarios 5

taskset -c 0-3 ./cpu_intensive_app
Limit an app to specific cores
taskset -c 4-7 ./realtime_app
Isolate cores for a real-time app
taskset -c 0 nginx
Pin Nginx workers to specific cores
taskset -c 1,2 mysql
Pin MySQL to specific cores
isolcpus=2,3
Kernel param: isolate CPUs 2,3 from scheduling at boot

Tips

  • CPU affinity reduces cache misses and boosts performance, but over-pinning can cause uneven load.
  • Real-time apps (HFT, A/V processing) suit isolated cores.
  • Under NUMA, binding CPU and memory nodes cuts cross-node access latency.
  • taskset -c's CPU-list format is more readable than hex masks; use it daily.
  • The isolcpus kernel param isolates CPUs at boot — more thorough than taskset but needs a reboot.
  • Multi-threaded processes need -a to set all threads, or only the main thread is affected.

Official References

Commands are compiled from the official docs below. Click to verify the latest usage.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us