在 Windows 中等效的任务集 [英] taskset equivalent in windows
问题描述
在 Linux 中,有 taskset 实用程序允许您为某个进程设置 CPU 亲和性.
In Linux, there's the taskset utility which allows you to set CPU affinity for a certain process.
Windows 环境中是否有等价物?
我想为我的产品设置最大 CPU 阈值,Windows 中是否有提供此功能的现有机制?
Is there an equivalent in the Windows environment?
I want to set a maximum CPU threshold for my product, is there any existing mechanism in Windows that offers this capabilities?
如果有帮助,我的产品是在 .Net 中开发的
If its any help, my product is developed in .Net
谢谢
推荐答案
是的,有:
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 <十六进制关联掩码>
.
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
,依此类推.
If you'd like to bind to CPU 0 only, then specify affinity mask of 0x1
. To bind to CPU 1 the mask should be 0x2
. To bind to CPU 0 and CPU 1 the mask should be 0x3
, and so on.
您还可以通过将相同的十六进制掩码值分配给可通过调用 System.Diagnostics.Process.GetCurrentProcess 获得的当前进程实例的
:ProcessorAffinity
属性,在代码中设置 CPU 亲和性()
You can also set the CPU affinity in code by assigning the same hexadecimal mask value to the ProcessorAffinity
property of the instance of the current process obtainable by calling System.Diagnostics.Process.GetCurrentProcess()
:
using System.Diagnostics;
Process.GetCurrentProcess().ProcessorAffinity = (IntPtr)0x3;
这篇关于在 Windows 中等效的任务集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!