Setting a process’ processor affinity in linux

Sometimes, people like me like to run stuff on a dedicated cpu instead of using all available cpu’s. The key to success here is this nifty tool: schedtool. Unfortunately, I didn’t find it anywhere in suse’s package database, nor the build service (if you know a repo or util package, please let me know).

But don’t worry, I guess nobody cares to make a separate package as it is such a small util. Just download the source from the website and make/make install (configure isn’t even needed).

Then, to run a process, in this case a dir listing, on CPU0, use:

schedtool -a 0x1 -e ls -la

-e specifies the command to execute
-a is followed by a bitmask in which each bit represents a CPU.

I have found that somehow it is best to always use the hexadecimal notation, even if your number is less than 10.

Leave a Reply

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