Set affinity with start /AFFINITY command on Windows 7

bradvido picture bradvido · Oct 13, 2011 · Viewed 72k times · Source

I am using the start /AFFINITY [n] [.exe] command to start an executable with the specified affinity. I have a system with 8 processors (1,2,3,4,5,6,7,8). I'd like to set the process to use all of the odd processors (1,3,5,7). I cannot figure out how to do this and would like to know if it's possible using the start command. If not, is there an alternate command-line way of doing it?

The help for the start command wasn't particularly useful:

 AFFINITY    Specifies the processor affinity mask as a hexadecimal number.
             The process is restricted to running on these processors.

             The affinity mask is interpreted differently when /AFFINITY and
             /NODE are combined.  Specify the affinity mask as if the NUMA
             node's processor mask is right shifted to begin at bit zero.
             The process is restricted to running on those processors in
             common between the specified affinity mask and the NUMA node.
             If no processors are in common, the process is restricted to
             running on the specified NUMA node.

Answer

ladenedge picture ladenedge · Oct 13, 2011

AFFINITY works with a hexidecimal mask that should allow granular control of all of your processors. Note that the rightmost bit specifies the lowest-order CPU (0) (see KB 299641).

For the case in question, 0xAA (10101010) requests that your process run using processors 1, 3, 5 and 7, but not 0, 2, 4 or 6. Be sure to leave out the '0x' on the command line.

 start /affinity AA app.exe

Other examples:

 start /affinity 1 app.exe     (only use CPU 0)
 start /affinity 2 app.exe     (only use CPU 1)
 start /affinity 1F app.exe    (only use CPUs 0, 1, 2, 3, and 4)