2008-08-07 75 views
58

是否有Windows命令的等價物,不錯Windows相當於'nice'

我正在尋找一些我可以在命令行使用的東西,而而不是從任務管理器的「設置優先級」菜單。

我試圖在Google上找到這件事的做法已經被那些不能提出更好的形容詞的人所挫敗。

回答

55

如果你想啓動一個過程中,你可以使用內置時設置優先級-in start命令:

START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED] 
     [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL] 
     [/WAIT] [/B] [command/program] [parameters]

使用low through belownormal選項設置啓動的命令/程序的優先級。看起來像最直接的解決方案。沒有下載或腳本寫作。其他解決方案可能在已經運行的procs上工作。

+5

爲了讓`start`行爲更像`nice`,使用`/ WAIT`和`/ B`選項,使端子輸出到同一個窗口。 – 2014-09-02 17:52:08

4

也許你要考慮使用ProcessTamer說,「使自動化」降級的過程或基於您的設置升級進程優先級。

我一直在使用它兩年。這非常簡單但非常有效!

6

如果您使用PowerShell,您可以編寫一個腳本來改變進程的優先級。我發現了Monad blog以下的PowerShell功能:

function set-ProcessPriority { 
    param($processName = $(throw "Enter process name"), $priority = "Normal") 

    get-process -processname $processname | foreach { $_.PriorityClass = $priority } 
    write-host "`"$($processName)`"'s priority is set to `"$($priority)`"" 
} 

從PowerShell提示符下,你會做一些行:

set-ProcessPriority SomeProcessName "High" 
3

http://techtasks.com/code/viewbookcode/567

# This code sets the priority of a process 

# --------------------------------------------------------------- 
# Adapted from VBScript code contained in the book: 
#  "Windows Server Cookbook" by Robbie Allen 
# ISBN: 0-596-00633-0 
# --------------------------------------------------------------- 

use Win32::OLE; 
$Win32::OLE::Warn = 3; 

use constant NORMAL => 32; 
use constant IDLE => 64; 
use constant HIGH_PRIORITY => 128; 
use constant REALTIME => 256; 
use constant BELOW_NORMAL => 16384; 
use constant ABOVE_NORMAL => 32768; 

# ------ SCRIPT CONFIGURATION ------ 
$strComputer = '.'; 
$intPID = 2880; # set this to the PID of the target process 
$intPriority = ABOVE_NORMAL; # Set this to one of the constants above 
# ------ END CONFIGURATION --------- 

print "Process PID: $intPID\n"; 

$objWMIProcess = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2:Win32_Process.Handle=\'' . $intPID . '\''); 

print 'Process name: ' . $objWMIProcess->Name, "\n"; 

$intRC = $objWMIProcess->SetPriority($intPriority); 

if ($intRC == 0) { 
    print "Successfully set priority.\n"; 
} 
else { 
    print 'Could not set priority. Error code: ' . $intRC, "\n"; 
}