How to launch a process with CPU affinity set

I was trying to get this internet explorer process launched so that it can use only 4 processors on a 8 core machine. It wasnt as easy as I thought initially.

Finally I figured out an easy way and I am sure it will save a lot of time for others who require to do this.

There are few different methods we can do this.

  1. 1st Method
    1. System wide we can set the boot.ini setting to use /numproc=4 so that the machine uses only 4 cores irrespecitve of the number of cores available (provided the available cores is more than 4)
  2. 2nd Method
    1. Launch a command window and run the highligted commands from the next steps
    2. Run cd c:\program files (x86)\internet explorer
    3. Run start /affinity F iexplore.exe
    4. Now you can check the affinity from the task manager OR process explorer.

 

If you are using start /affinity, you will need to specify the value for affinity which is a hexadecimal value. Here is a simple way of calculating this affinity value.

Here is how the processors will be numbered. This may be different based on the number of nodes. However the calculation remains the same. Please use terms cores/processors interchangeably.

 

CPU ID

Associated value (n)

Formula (2n-1)

Affinity in Hex (h)

CPU0

1

1

1

CPU1

2

3

3

CPU2

4

7

7

CPU3

8

15

F

CPU4

16

31

1F

CPU5

32

63

3F

CPU6

64

127

7F

CPU7

128

255

FF

 

Based on the above formula, you can run the following command. Replace hwith the value in the Affinity column. This will result in using all the CPU’s listed above the specified value including the current.

 

Example:

If you specify a value of 1F  for affinity, it will use CPU4, CPU3, CPU2, CPU2 and CPU0

 

If you want to use specific CPU’s, you will need to SUM the associated values and use the corresponding HEX value.

Example:

If you want to run a process on CPU0 & CPU4, you can sum the values

 

Start /affinity h iexplore.exe

 

Enjoy launching processes with CPU affinity :)

Comments

  • Anonymous
    April 15, 2012
    Thanks for sharing this.Is there a way to Start a Application with first set of 4 CPU and Another application with Another set (Remaining 4 cpu's)/

  • Anonymous
    December 20, 2012
    The comment has been removed

  • Anonymous
    January 22, 2013
    Thanks for this great information. But how do i run only on CPU 6? I need to direct some parallel batch skripts to a specific CPU. For example Batch 1 to CPU 0, Batch 2 to CPU 2, Batch 3 to CPU 4, Batch 4 to CPU 6. I figured out the first ones, but do not get the clue for CPU 6.

  • Anonymous
    April 15, 2013
    HEX(64) should run on the process on PROC 6. Use HEX(Associated Value) for specific process

  • Anonymous
    February 26, 2014
    how do i run a specific on a specific cpu?

  • Anonymous
    March 19, 2014
    The comment has been removed

  • Anonymous
    August 26, 2014
    is the formula right? should it be 2*n-1

  • Anonymous
    September 05, 2014
    The formula is right. Two possibilities in a bit (0 or 1) powed to the bit offset. Is a geometric progression and you need an AND operation to sum the numbers. This is called boolean algebra.

  • Anonymous
    December 21, 2015
    Hi! Is there a way to tell the OS that i want this process to run on 2 cores of 4 but i do not want to specify the cores. I don't want to specify the cores because it should be changed based on the core's temperature. Ideally it would rotate between core0&2 and core1&3. I have seen this in action using linux and i am wondering if it can be done in Windows.