【问题标题】:taskset equivalent in windowsWindows中的等效任务集
【发布时间】:2012-06-05 11:54:35
【问题描述】:
在 Linux 中,taskset 实用程序允许您为某个进程设置 CPU 亲和性。
在 Windows 环境中是否有等价物?
我想为我的产品设置最大 CPU 阈值,Windows 中是否存在提供此功能的现有机制?
如果有帮助,我的产品是在 .Net 中开发的
谢谢
【问题讨论】:
标签:
c#
windows
performance
【解决方案1】:
是的,有:
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,依此类推。
您还可以通过将相同的十六进制掩码值分配给可通过调用System.Diagnostics.Process.GetCurrentProcess() 获得的当前进程实例的ProcessorAffinity 属性,在代码中设置CPU 亲和性:
using System.Diagnostics;
Process.GetCurrentProcess().ProcessorAffinity = (IntPtr)0x3;