2012-05-31 18 views
2

在Linux中,有taskset實用程序,它允許您爲特定進程設置CPU關聯。windows中等價的任務集

在Windows環境中是否有等價物?
我想爲我的產品設置最大CPU閾值,Windows中是否存在提供此功能的任何現有機制?

如果它的任何幫助,我的產品是.NET中

開發

感謝

+1

[親和力換](HTTP:/ /sourceforge.net/projects/affinitychanger/)自動執行此操作,或者簡單地使用[ProcessMonitor](http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx)進行手動操作就是兩個例子。請注意,「親和力」和「閾值」雖然並不完全相同。一般來說,對於程序在工作時消耗100%CPU(並且阻止,即在無所事事時消耗0%),它是非常好的。 – Damon

回答

3

是的,有:

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;