Windows 中“nice”的等效词
-
08-06-2019 - |
题
Windows 中是否有相当于 Unix 命令的命令? 好的?
我正在专门寻找可以在命令行中使用的东西,并且 不是 任务管理器中的“设置优先级”菜单。
我在谷歌上寻找这个的尝试被那些想不出更好形容词的人挫败了。
解决方案
如果您想在启动进程时设置优先级,可以使用内置启动命令:
START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED] [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL] [/WAIT] [/B] [command/program] [parameters]
使用低到低于正常选项来设置启动的命令/程序的优先级。似乎是最直接的解决方案。无需下载或编写脚本。其他解决方案可能适用于已经运行的进程。
其他提示
如果你使用 电源外壳, ,您可以编写一个脚本来更改进程的优先级。我在上找到了以下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"
也许你想考虑使用 流程驯服者 根据您的设置“自动化”降级或升级进程优先级的过程。
我已经使用它两年了。非常简单但是非常有效!
从 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";
}
不隶属于 StackOverflow