Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorstaskset lets you set or retrieve CPU affinity for a Linux process, or launch a command with a chosen affinity. Use a hexadecimal bit mask for compact CPU selection, or -c for readable CPU numbers and ranges. A successful change means Linux accepted the affinity mask; it does not necessarily mean the process moved to a selected CPU immediately.
What taskset does
taskset is a util-linux command for setting or retrieving a process’s CPU affinity. CPU affinity is the set of logical CPUs on which a thread is eligible to run. The scheduler observes that set, though it may already keep a workload on a CPU when practical. Some kernel per-CPU threads do not allow their affinity to be changed. See the taskset(1) manual.
The command has two main forms:
taskset [options] mask command [argument...]launches a command with the selected affinity.taskset [options] -p [mask] pidreads or changes affinity for an existing process.
Launch a command with selected CPUs
To start a command with a hexadecimal CPU mask, put the mask before the command:
taskset 0x3 mycommand
This mask selects logical CPUs 0 and 1. To use readable CPU numbers, add -c (also spelled --cpu-list):
#1 Best Overall
taskset --cpu-list 0-2,6 mycommand
That list selects logical CPUs 0, 1, 2, and 6. A stride can select every other CPU in a range:
taskset -c 0-10:2 mycommand
This expands to CPUs 0, 2, 4, 6, 8, and 10. The specified CPUs still have to be valid for the task under the system’s current restrictions.
Read or change affinity for an existing PID
Use -p to operate on an existing process ID (PID). With no mask, taskset reports the current affinity; with a mask, it requests a change:
taskset -p 1234
taskset -p 0x3 1234
For CPU numbers or ranges instead of a hexadecimal mask, combine -p with -c:
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →taskset -pc 0-3 1234
Here, 1234 is the PID to inspect or modify. PID 0 refers to the taskset process itself. Use -a (--all-tasks) when you want to retrieve or set affinity for all threads belonging to a PID; without it, the Linux affinity operation applies to an individual thread. The -h and -V options display help and version information, respectively.
How hexadecimal CPU masks map to CPUs
A mask is a bit field: its lowest-order bit represents logical CPU 0, the next bit represents CPU 1, and each succeeding bit represents the next CPU number. Bits set to 1 select those CPUs.
Rank #4
| Mask | Selected logical CPUs |
|---|---|
0x00000001 |
CPU 0 |
0x00000003 |
CPUs 0 and 1 |
0x32 |
CPUs 1, 4, and 5 |
For example, 0x32 is binary 110010; counting bits from the right starting at bit 0, the set bits are 1, 4, and 5. If you do not want to translate bits, use -c with a list such as 1,4-5.
Permissions, restrictions, and what success means
You can change affinity for a process you own. Changing another user’s process requires the CAP_SYS_NICE capability. The taskset manual permits reading the affinity mask of any process; the underlying sched_setaffinity(2) call can report EPERM when the caller lacks the required identity or capability. See the sched_setaffinity(2) manual.
Best Value
A successful set means the kernel accepted the requested mask; it does not guarantee immediate migration. A thread will not migrate outside its accepted affinity, but it may still be running on its current CPU when the command returns. The manual illustrates this with a kernel thread that can retain its CPU after a successful change.
The effective set of CPUs can also be narrower than the requested mask. Linux intersects a thread’s mask with CPUs that are physically present and with any cpuset restrictions; cpusets can be imposed by containers or other system policy, and the kernel may silently narrow the effective set. A mask with no valid CPU is rejected. An illegal mask produces an error and exit status 1.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Affinity is per thread, not a universal process switch
Linux defines CPU affinity as a per-thread attribute. Threads in one process can therefore have different masks, which is why -a matters when you intend to affect every thread associated with a PID. At the system-call level, affinity can be changed independently for individual threads. A child created with fork() inherits its parent’s mask, and the mask is preserved across execve().
When pinning can help—and when not to expect a speedup
Keeping a thread on a dedicated CPU can reduce cache invalidation costs that occur when execution moves between CPUs. That makes affinity a possible performance technique, not a general speed switch. Results depend on workload behavior, CPU topology, contention, and kernel policy; restricting a task can also leave it with fewer CPUs on which to run.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Use taskset when you need to constrain or inspect CPU eligibility. It is not a substitute for understanding cpuset or container limits, and successful pinning is not proof that a workload will run faster.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

