在 windows 中限制用户的 CPU 使用率

Limiting the CPU utilization of a user in windows

我想知道有什么方法可以限制windows中的用户名使用cpu的次数吗?例如,有 8 个核心,我想将用户的全局 cpu 使用限制为 6。因此,他不能 运行 超过 6 个串行作业(每个使用一个核心)。

在 Linux 中,这可以通过脚本来完成。但即使使用 powershell 脚本,我也没有看到任何类似的东西。那是不是就不能做了?

关键字是A​​ffinity。 亲和力从 0 开始,是第一个核心。 Affinity 是位图

10000000 = first core 01000000 = second core 11000000 = first and second core 00100000 = third core 10100000 = first and third core 11100000 = first second and third core

function Set-Affinity([string]$Username,[int[]]$core){
    [int]$affinty = 0
    $core | %{ $affinty += [math]::pow(2,$_)}
    get-process -IncludeUserName | ?{$_.UserName -eq $Username} | %{
        $_.ProcessorAffinity = $affinty
    }
}

Set-Affinity -username "TESTDOMAIN\TESTUSER" -core 0,1,2,3