Possible Duplicate:
How can I set the processor affinity of a process on Linux?

Computer CPUs have many cores insde them nowadays.

I have always wondered if there is a way to, when I start a process on the Linux command line, specify which particular core or cores that process might use?

For example, can I start a massive grep task and say "use ALL of CPU2 for yourself".

Or could I start a find task and say "never leave CPU3".

Or maybe I could start a video decoding task and say "use whatever is available on CPU1 and CPU2"

OR, is there no way to do this because it is not needed and the OS is doing this kind of stuff intelligently by itself (based on nice levels and general resource usage of the process etc)


marked as duplicate by Mat, jasonwryan, Gilles, daisy, Renan Sep 12 '12 at 19:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


What you are wondering about is CPU Affinity. I found that there was a good explanation of CPU affinity on NixCraft. But note that the Linux kernel is indeed, as you say, already making intelligent choices.

  • 2
    And thankfully I don't know of many linux apps that charge you using a per-core licence (MSSQL I'm looking at you) – Rqomey Sep 10 '12 at 14:18

See the taskset utility. Should be exactly what you're looking for.

Not the answer you're looking for? Browse other questions tagged or ask your own question.