代码之家  ›  专栏  ›  技术社区  ›  mahmood

限制windows中用户的CPU利用率

  •  0
  • mahmood  · 技术社区  · 8 年前

    我想知道在windows中是否有办法通过用户名来限制cpu的使用量?例如,有8个内核,我想将一个用户的全局cpu使用率限制为6,因此,他不能运行超过6个串行作业(每个作业使用一个内核)。

    在Linux中,这可以通过脚本实现。但我还没有看到任何类似的东西,甚至与powershell脚本。这是不是意味着,这不能做?

    1 回复  |  直到 8 年前
        1
  •  2
  •   ArcSet    8 年前

    这个关键词是 关联从0开始,0是第一个核心。 关联是位图

    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