SHARE
Facebook X Pinterest WhatsApp

Using Taskset for Priority Tasks

Written By
thumbnail Joe Brockmeier
Joe Brockmeier
Dec 7, 2010
ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



More open source server tools

Unless you’re using a really old machine or cheap netbook, almost any system you touch with Linux these days is going to be a multiprocessor system. Any server machine deployed within the past five years should have at least two CPUs, and most desktops released in the past three years have at least two cores. For a number of reasons, you might want to “pin” some tasks so they run exclusively on a single CPU or set of CPUs.

A tisket, a tasket, be sure to use the open source server tool taskset for priority tasks.

Whether you want to ensure resources for a process, ensure that a process doesn’t hog all system resources or improve a process that doesn’t scale well to multiple CPUs, you can use taskset to assign a task to specific CPUs. It’s pretty simple.

Using taskset, you “bond” a process to a CPU. Let’s say you want to run Google Chrome on one CPU. You’d run something like this:

taskset 0x00000001 google-chrome

Now Chrome will be limited to CPU 0 (0x00000001 is the “mask” for CPU 0). If you wanted to assign it to two CPUs, you would use taskset 0x00000003 instead. Or you could use the -c option and specify the CPUs by numerical ranges. See the taskset man page for more on that.

To see what processors a task is assigned to, try running taskset -p XXXX, where XXXX is the process ID (PID). If you’re on a two-core system, for example, and haven’t set the affinity, it will return 3. If you’ve assigned it to both cores/CPUs, then it will return 3. I don’t make the syntax, I just write about it …

Is this going to speed up your system or be worth doing with all tasks? Nope. It is, however, something you can try to experiment with when you’re having performance problems or having issues with a process/application causing problems with the rest of the system. I’d recommend testing it out on your desktop or test systems before attempting it in a production environment — but with the right combination, you might be able to solve some system problems in short order.

Joe ‘Zonker’
Brockmeier
is a freelance writer and editor with more than 10 years covering IT. Formerly the openSUSE Community Manager for Novell, Brockmeier has written for Linux Magazine, Sys Admin, Linux Pro Magazine, IBM developerWorks, Linux.com, CIO.com, Linux Weekly News, ZDNet, and many other publications. You can reach Zonker at jzb@zonker.net and follow him on Twitter.

Follow ServerWatch on Twitter

thumbnail Joe Brockmeier

Joe Brockmeier is the editorial director of the Red Hat Blog. He joined Red Hat in 2013 as part of the Open Source and Standards (OSAS) group, now the Open Source Program Office (OSPO). Prior to Red Hat, Brockmeier worked for Citrix on the Apache OpenStack project, and was the first OpenSUSE community manager for Novell between 2008-2010. Brockmeier also has an extensive history in the tech press and publishing, having been editor-in-chief of Linux Magazine, editorial director of Linux.com, and a contributor to LWN.net, ZDNet, UnixReview.com, and many others.

Recommended for you...

What Is a Container? Understanding Containerization
What Is a Print Server? | How It Works and What It Does
Nisar Ahmad
Dec 8, 2023
6 Best Linux Virtualization Software for 2024
What Is a Network Policy Server (NPS)? | Essential Guide
ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.