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)



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.

| improve this answer | |
  • 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.

| improve this answer | |

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