GuidesUsing Taskset for Priority Tasks

Using Taskset for Priority Tasks

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

Get the Free Newsletter!

Subscribe to Daily Tech Insider for top news, trends & analysis

Latest Posts

Related Stories