gpt4 book ai didi

c# - Windows 中的等效任务集

转载 作者:可可西里 更新时间:2023-11-01 10:07:57 28 4
gpt4 key购买 nike

在 Linux 中,有 taskset实用程序,它允许您为某个进程设置 CPU 亲和性。

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

如果有帮助的话,我的产品是用 .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 <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.

如果您只想绑定(bind)到 CPU 0,请指定 0x1 的关联掩码.要绑定(bind)到 CPU 1,掩码应为 0x2 .要绑定(bind)到 CPU 0 和 CPU 1,掩码应为 0x3 , 等等。

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

using System.Diagnostics;

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

关于c# - Windows 中的等效任务集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10829974/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com