在Windows 7上使用start/AFFINITY命令设置关联

bra*_*ido 20 command-line affinity windows-7

我正在使用该start /AFFINITY [n] [.exe]命令以指定的亲缘关系启动可执行文件.我有一个带8个处理器的系统(1,2,3,4,5,6,7,8).我想设置进程使用所有奇数处理器(1,3,5,7).我无法弄清楚如何做到这一点,并想知道是否可以使用start命令.如果没有,是否有另一种命令行方式呢?

start命令的帮助不是特别有用:

 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.
Run Code Online (Sandbox Code Playgroud)

lad*_*dge 23

AFFINITY使用十六进制掩码,可以对所有处理器进行精细控制.请注意,最右边的位指定最低阶CPU(0)(请参阅知识库文章299641).

对于有问题的情况,0xAA(10101010)请求您的进程使用处理器1,3,5和7运行,但不是0,2,4或6.确保在命令行中省略'0x'.

 start /affinity AA app.exe
Run Code Online (Sandbox Code Playgroud)

其他例子:

 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)
Run Code Online (Sandbox Code Playgroud)


小智 9

要获得正确的十六进制数,请想象你的核心是平面格式8765 4321(对于8核CPU)向后(但不像1234 5678)

要激活核心7,6和3,请0x64为亲和力键入数字:

/AFFINITY 0x64
Run Code Online (Sandbox Code Playgroud)

为了更好的外观,匹配和比较:0110 0100- number = 0x64(8765 4321) - 核心

对于@ladenedge示例:/AFFINITY AA 1010 1010- number = 0xAA(8765 4321) - 核心

另请参阅:在Windows 7,8或Vista中启动分配给特定CPU的应用程序

  • 只是添加一个简单的方法来做到这一点......一旦你反过来考虑你的处理器ID,只需进入计算并切换到程序员模式.在左侧设置二进制"Bin",然后键入代码以打开和关闭每个,然后点击"Hex".那将为您提供开始代码. (2认同)

小智 5

有关您自己的计算需求的更多信息:

CPU ID  CPU value (dec)
0       001 (= 2^0)
1       002 (= 2^1)
2       004 (= 2^2)
3       008 (= 2^3)
4       016 (= 2^4)
5       032 (= 2^5)
6       064 (= 2^6)
7       128 (= 2^7)
Run Code Online (Sandbox Code Playgroud)

最后:

  • CPU ID 0、1、2、3、4、5、6、7的掩码:255(单个CPU十进制值的总和),即十六进制的“FF”掩码
  • CPU ID 0、2、4、6 的掩码:85(各个 CPU 十进制值的总和),即十六进制的“55”掩码

参考:在https://msdn.microsoft.com/en-US/library/ms187104.aspx搜索“这些是 8-CPU 系统的关联掩码值”模式。