在Windows中等效的任务集

时间:2012-05-31 08:30:11

标签: c# windows performance

在Linux中,有taskset实用程序,它允许您为特定进程设置CPU关联。

Windows环境中是否存在等效内容?
我想为我的产品设置最大CPU阈值,Windows中是否存在提供此功能的现有机制?

如果有任何帮助,我的产品是用.Net开发的

由于

1 个答案:

答案 0 :(得分:3)

是的,有:

Starts a separate window to run a specified program or command.

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
  [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
  [/NODE <NUMA node>] [/AFFINITY <hex affinity mask>] [/WAIT] [/B]
  [command/program] [parameters]

特别是选项/AFFINITY <hex affinity mask>

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.

如果您只想绑定到CPU 0,请指定0x1的关联掩码。要绑定到CPU 1,掩码应为0x2。要绑定到CPU 0和CPU 1,掩码应为0x3,依此类推。

您还可以通过将相同的十六进制掩码值分配给可通过调用ProcessorAffinity获得的当前进程实例的System.Diagnostics.Process.GetCurrentProcess()属性来设置代码中的CPU亲和性:

using System.Diagnostics;

Process.GetCurrentProcess().ProcessorAffinity = (IntPtr)0x3;