Pin a process to CPU cores with taskset

Restrict a noisy or performance-critical process to chosen cores with CPU affinity.

LinuxProcessesperformancecpucpu-affinityLow risk
Run taskset -cp 0-3 PID to confine a running process to cores 0-3, or launch a new one with taskset -c 0-3 command.

01Command

Command
$ taskset -cp 0-3 12345

02What it does

taskset sets the CPU affinity mask of a process, deciding which cores the scheduler may run it on. Keeping a compiler or game server on fixed cores reduces cache thrashing and leaves other cores free for your desktop. -cp prints and then sets the affinity of an existing PID, and -a includes all threads of the process.

03Risk

RiskLow risk
Requirementstaskset is part of util-linux; available on all Linux distros. No root needed for your own processes.
!Warning: Pinning is a tuning tool, not a speed boost: confining a multi-threaded program to too few cores will slow it down. In containers and VMs, the core numbers taskset shows may not match the physical host topology.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • taskset(1) — Arch Manual Pages
    Arch Linux · community · 2026-09-17
    Evidence: Describes taskset as setting or retrieving a process CPU affinity, with -c/--cpu-list and -p/--pid usage shown.
  • taskset(1) — Debian bookworm
    Debian Manpages · community · 2026-09-17
    Evidence: Documents taskset [options] -p [mask] pid with --pid, --cpu-list and --all-tasks options for setting CPU affinity of running processes.

Last verified: 2026-09-19 · Category: System & Settings

06Related solutions