October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Linux taskset: Set and Read CPU Affinity with Masks or CPU Lists

Use Linux taskset to launch commands or manage a PID's CPU affinity with hexadecimal masks or readable CPU lists. This guide covers bit mapping, threads, permissions, cpusets and migration behavior.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

taskset sets or reads a Linux process’s CPU affinity—the logical CPUs on which it is allowed to run—and can start a command with that restriction already applied. Use a hexadecimal mask for compact bit-level control, or -c for readable CPU numbers and ranges. A successful change means the kernel accepted the new allowed set; it does not promise that the thread has migrated immediately.

What taskset does

The taskset(1) command, supplied by util-linux, manages CPU affinity for processes. Linux schedules a thread only on CPUs included in its affinity mask, subject also to cpuset and other kernel restrictions. The command can:

  • launch a new command with a selected affinity;
  • display the affinity of an existing process;
  • change the affinity of an existing process; and
  • operate on every thread in a process when requested.

Affinity is a scheduling constraint, not a performance guarantee. Pinning can reduce cache disruption caused by movement between CPUs, but contention, CPU topology, workload behavior and kernel policy determine whether an application actually improves.

Command syntax

taskset [options] mask command [argument...]
taskset [options] -p [mask] pid

The first form starts a command. The second reads or changes the affinity of an existing process identified by its PID.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Lenovo IdeaPad Slim 3 Linux Laptop, 15.6" FHD Touchscreen Laptop, 8-Core AMD Ryzen 7 5825U, 16GB RAM, 512GB SSD, Keypad, SD Card Reader, Stylus Pen + External Portable SSD + USB Hub, Linux Ubuntu OS
  • Powerful Linux Laptop: This IdeaPad Slim 3 Laptop comes pre-installed with Ubuntu Linux, offering fast performance, robust security, and a clean, user-friendly experience. Enjoy full customization, seamless hardware compatibility, and access to thousands of open-source apps. Whether you're working, creating, or coding, it's built to keep up with everything you do.
  • A Multitasking Master: The latest AMD Ryzen 7 5825U processor (up to 4.5 GHz) delivers powerful performance with 8 cores and 16 threads for smooth multitasking. Integrated AMD Radeon Graphics provide crisp visuals for streaming, browsing, photo editing, and casual gaming. With smart machine intelligence, it adapts to your needs for a fast, responsive experience.
  • 15.6" Full HD Display: The IdeaPad Slim 3 boasts an 88% screen-to-body ratio for a floating, edge-to-edge visual experience. TÜV Low Blue Light certification reduces eye strain, making it perfect for long work or study sessions.
  • Military-Grade Durability: The smart IdeaPad Slim 3 combines portability and durability, letting you work, study, and play on the go. With a profile 10% slimmer than the previous generation, it's lightweight yet military-grade rugged, ready for anything, anywhere.
  • Versatile Connectivity: Enjoy the security of a built-in webcam with a privacy shutter. Connect effortlessly with multiple ports: 2x USB A, 1x USB C, 1x HDMI, 1x SD Card Reader, 1x Headphone/Microphone combo. Bundle comes with Stylus Pen, 256GB Portable SSD and 5-in-1 Docking Station.

Start a command on selected CPUs

Use a hexadecimal mask

taskset 0x3 mycommand --input file.dat

Bits in the mask correspond to logical CPU numbers, with bit 0 representing CPU 0. Therefore, 0x3 (binary 11) allows CPUs 0 and 1. A mask of 0x1 allows only CPU 0.

Mask Allowed logical CPUs Reason
0x1 CPU 0 Only bit 0 is set
0x3 CPUs 0 and 1 Bits 0 and 1 are set
0x32 CPUs 1, 4 and 5 Bits 1, 4 and 5 are set

Use a mask that contains at least one valid CPU. A mask with no valid CPU produces an error.

Use readable CPU lists

taskset --cpu-list 0-2,6 mycommand
# Equivalent short option
taskset -c 0-2,6 mycommand

CPU-list syntax accepts individual numbers, comma-separated lists and ranges. A stride suffix selects regular intervals:

Rank #2
HP 17 Business Laptop - Linux Mint Cinnamon - Intel Quad-Core i5-10210U, 32GB RAM, 1TB PCIe NVMe SSD + 1TB Storage HDD, 17.3" Inch HD+ (1600x900) Display
  • Intel Core i5-10210U (up to 4.2GHz) - 1TB PCIe NVMe + 1TB HDD - 32GB DDR4 SDRAM
  • 17.3" HD+ (1600x900) Display, Intel UHD Graphics 620
  • Built in HD 720p Webcam with Microphone - Bluetooth Version4.2
  • I/O Ports: 2x USB 3.1 (Data Only), 1x USB 2.0, 1x HDMI, 1x Headphone/Microphone Combo Jack
  • Linux Mint Cinnamon 64-Bit - 6-Row Keyboard w/ Full Numberpad
taskset -c 0-10:2 mycommand

This allows CPUs 0, 2, 4, 6, 8 and 10. CPU numbers are logical CPU IDs exposed by Linux, not necessarily physical cores; simultaneous multithreading can give multiple logical IDs per physical core.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read or change an existing process

Read the current affinity

taskset -p PID

Replace PID with the process ID. For example:

taskset -p 4242

In query mode, taskset reports the process’s current mask. Reading another user’s process is generally permitted under the command’s documented rules.

Set a hexadecimal mask

taskset -p 0x3 4242

This requests CPUs 0 and 1 for PID 4242. The -p option tells taskset to operate on an existing PID instead of launching a command.

Rank #3
Lenovo Business Laptop - Linux Mint (Cinnamon) - Intel i5-1335U, 16GB RAM, 256GB SSD, 15.6" FHD 1920x1080 Display, Full Keyboard, Fast Charging
  • Intel Core i5-1335U Processor (12M Cache, 12 Threads, up to 4.6 GHz) - 256GB Solid State Drive - 16GB DDR4 SDRAM
  • 15.6" FHD (1920x1080) Non-Touch Anti-Glare Display - Intel UHD 620 Integrated Graphics - Stereo Speakers
  • 720p HD Webcam with Privacy Shutter. Integrated Microphone - Intel Dual Band Wireless-AC (2x2) 8265, Bluetooth Version 4.2
  • I/O Ports: 2x USB 3.0, 1x USB 3.1 Type-C 3.1, Headphone/Mic Combo Port, 4-in-1 Card Reader, HDMI, Kensington Mini-Lock Slot
  • Linux Mint (Cinnamon) 64-Bit - Keyboard with Full NumberPad - Fast Charging

Set a CPU list

taskset -pc 0-3 4242

Here -p selects PID mode and -c interprets 0-3 as a CPU list. Combining short options in this form is supported by the taskset manual.

Processes, threads and the -a option

Linux stores affinity per thread. A process ID normally identifies one task, commonly the thread-group leader; other threads can have independent masks.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
taskset -a -pc 0-3 4242

-a (or --all-tasks) applies the operation to all tasks, meaning all threads belonging to the specified PID. Without -a, you may change only the task represented by that PID. If you need different CPU sets for individual threads, use the underlying per-thread scheduling interfaces rather than assuming one process-wide setting.

A child created with fork() inherits its parent’s affinity, and the setting is preserved across execve(). Thus a command launched by taskset starts with the selected mask, and an executed program keeps it unless changed later.

Options at a glance

Option Purpose
-a, --all-tasks Read or set affinity for all threads belonging to a PID.
-c, --cpu-list Interpret the selection as CPU numbers, lists, ranges and strides.
-p, --pid Operate on an existing PID rather than launch a command. PID 0 refers to the taskset process.
-h, --help Show command help.
-V, --version Show the installed taskset version.

Permissions and errors

You can normally change affinity for a process you own. Changing another user’s process requires the CAP_SYS_NICE capability. Without the required identity or capability, the underlying sched_setaffinity(2) call reports EPERM, and taskset fails.

  • Invalid or empty selection: the mask contains no valid CPU, so the command reports an error.
  • Permission denied: you lack ownership or CAP_SYS_NICE for the target.
  • Kernel thread limitation: some per-CPU kernel threads cannot have their affinity changed.
  • Nonexistent PID: the target exited or the PID is incorrect.

Check the command’s exit status in a shell when scripting. In setting mode, success means the kernel accepted the requested mask; an illegal mask results in status 1.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
GMKtec G3S Mini PC Intel N95 Processor (Up to 3.4GHz) 8GB RAM 256GB M.2 SSD
  • 12th Intel Alder Lake N95 Processor – The GMKtec G3 S Mini PC is powered by the 12th Gen Intel N95 processor with 4 cores, 4 threads, 6MB cache and a burst frequency up to 3.4GHz. Compared with N100/N5105/N5100/N5095, the N95 delivers up to 36% overall performance improvement. Perfect for routine tasks, office work, and home entertainment, this compact mini desktop is more convenient than traditional bulky PCs.
  • 8GB RAM & 256GB SSD Storage – Pre-installed with 8GB DDR4 memory and a fast 256GB M.2 2242 SSD, the G3 S mini desktop offers quicker startup, smoother multitasking, and faster file transfers. Enjoy seamless performance whether you’re working on multiple applications, browsing, or streaming content.
  • Rich Interfaces & Connectivity – The G3 S mini computer comes equipped with USB 3.2 (up to 10Gbps), dual HDMI 2.0 (4K@60Hz), and a 3.5mm audio jack. With support for WiFi 5, Bluetooth 5.0, and Gigabit Ethernet (RJ45 1000MbE), it connects easily with monitors, projectors, printers, office equipment, and other peripherals, making it versatile for both home and business use.
  • Dual 4K Display Support – Featuring upgraded Intel UHD Graphics (up to 1000MHz), the G3 S supports 4K video playback and AV1 decoding for a smooth viewing experience. With dual HDMI outputs, you can connect two 4K@60Hz displays simultaneously, enabling efficient multitasking for work and entertainment.
  • GMKtec WARRANTY - GMKtec offers a 1-year limited GMKtec's warranty for each mini PC, starting from the date of the purchase. All defects due to design and workmanship are covered. With a professional after sales team always ready to attend to your needs, you can simply relax and enjoy your mini PC.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why a process may not move immediately

A successful set does not mean the thread instantly appears on a different CPU. The scheduler may leave it on its current CPU when that CPU remains in the newly allowed set, and even a narrower mask can take effect without an observable immediate migration. The taskset manual specifically demonstrates that a kernel thread can retain its current CPU after a successful affinity change.

The effective run set can be narrower than the mask you request. Linux intersects the requested affinity with CPUs that are physically present and with cpuset restrictions. Containers, service managers and cgroup configuration can therefore limit the CPUs available to a process even when taskset accepts a broader mask. A task cannot run outside that effective intersection.

Choosing between a mask and -c

Need Best form Example
Compact value for scripts or tooling Hexadecimal mask taskset 0x3 command
Human-readable CPU selection CPU list taskset -c 0-2,6 command
Change one task identified by PID -p plus mask or -c taskset -pc 2-5 PID
Ensure every thread receives the setting Add -a taskset -a -pc 2-5 PID

A safe workflow for pinning a running application

  1. Find and verify the target PID using your normal process-inspection tool.
  2. Inspect its current setting with taskset -p PID.
  3. Choose logical CPU IDs that are valid in the target’s environment.
  4. Apply a readable list, for example taskset -pc 2-3 PID, or use a mask when required by automation.
  5. Add -a if the application uses multiple threads and every thread must be restricted.
  6. Read the affinity again and interpret success as acceptance of the mask, not proof of immediate migration or improved performance.

How taskset relates to the kernel API

taskset is a command-line interface to Linux scheduling affinity operations, principally sched_setaffinity(2) and its corresponding retrieval operation. The kernel definition is per-thread: a thread’s affinity mask determines the CPUs on which it is eligible to run. taskset provides convenient process and all-thread handling, while cpusets and other policy layers can impose additional limits.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.