是否有Windows等效的Unix命令, nice ?
我特意在命令行中查找可以使用的内容,并且不来自任务管理器的“设置优先级”菜单。
我在Google上发现这种情况的尝试已被那些无法提出更好形容词的人所挫败。
答案 0 :(得分:60)
如果要在启动进程时设置优先级,可以使用内置的启动命令:
START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED] [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL] [/WAIT] [/B] [command/program] [parameters]
使用low through belownormal选项设置已启动命令/程序的优先级。似乎是最直接的解决方案。没有下载或脚本编写。其他解决方案可能适用于已经运行的过程。
答案 1 :(得分: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"
答案 2 :(得分:4)
也许您要考虑使用ProcessTamer根据您的设置“自动化”降级或升级流程优先级的过程。
我已经使用它两年了。它非常简单但非常有效!
答案 3 :(得分: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";
}
答案 4 :(得分:1)