Run a program on one CPU core in Linux

Modern computers use CPUs with multiple cores for performance reasons. Software can take advantage of that and use both cores to run separate threads but sometimes it’s useful if you can force a process to use one core rather than both.

In Linux that’s easy to do. If you’re using Ubuntu or Debian grab the schedutils package:

sudo apititude install schedutils

That will install a program called “taskset” which is a tool to “retrieve or set a process’s CPU affinity”. It’s really easy to use too.

I wanted to force Bibblelabs on to one core while importing photos.

# ps auxw|grep bibble
donncha 19482 78.7 33.1 1090388 681220 ? RNl 09:56 77:28 ./bibblepro
# taskset -p 19482
pid 19482’s current affinity mask: 3
# taskset -p 01 19482
pid 19482’s current affinity mask: 3
pid 19482’s new affinity mask: 1

The app is still heavy on the system, and “System Monitor” doesn’t suddenly show 0% usage on one CPU because I’m also running Firefox, Xchat, X, Gnome Terminal but I’d almost swear the browser window refreshes faster.

PS. Thanks to whoever told me about this on Twitter a while back. It had slipped my mind and I had to search for it again. Blogging it to remember it!