How do I set the group and affinity of a Windows executable from the command line
You can use the /affinity
flag using the start
command to specify the cores a process should use.
Usage
start /affinity n foo.exe -arguments
So, your shortcut would look like:
c:\windows\system32\cmd.exe /C start /affinity n foo.exe -arguments
where n is
CPU core number +1.
So to run on Core 0 it'd be:
c:\windows\system32\cmd.exe /C start /affinity 1 foo.exe -arguments
.
Source
Specifying multiple cores
Assume a CPU has 4 cores. To specify the cores to use:
-
Visualize the cores as an array with the length of the array equal to the number of cores. The cores will be arranged in descending order from right to left:
[CPU3, CPU2, CPU1, CPU0]
-
Now, replace cores you would like your process to use with 1 and those you won't with 0. Assuming I want my process to use core 3 & 1, my array would like this:
[0,1,0,1]
-
"Pop" the elements of the array to a string. Now it would be represented as
0101
. -
Assume the string is in binary and convert it to hexadecimal. Now it would be
0x5
-
Now use the same command
start /affinity n foo.exe -arguments
but nown
will be0x5
, givingstart /affinity 0x5 foo.exe -arguments
Source
Notes:- The source explains the visualization as a binary string, not an array( check it out). I find this a bit confusing so I explained using an array.
- The source does not specify that you must prefix
0x
to show it's hexadecimal in the command. Readingstart /?
specifies it is to be hex.