Windows 相当于“nice”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4208/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows Equivalent of 'nice'
提问by Ryan Fox
Is there a Windows equivalent of the Unix command, nice?
是否有 Windows 等效的 Unix 命令,很好吗?
I'm specifically looking for something I can use at the command line, and notthe "Set Priority" menu from the task manager.
我特别在寻找可以在命令行中使用的东西,而不是任务管理器中的“设置优先级”菜单。
My attempts at finding this on Google have been thwarted by those who can't come up with better adjectives.
我在谷歌上找到这个的尝试遭到了那些无法想出更好形容词的人的阻挠。
采纳答案by Stephen Pellicer
If you want to set priority when launching a process you could use the built-in STARTcommand:
如果要在启动进程时设置优先级,可以使用内置的START命令:
START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
[/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
[/WAIT] [/B] [command/program] [parameters]
Use the low through belownormal options to set priority of the launched command/program. Seems like the most straightforward solution. No downloads or script writing. The other solutions probably work on already running procs though.
使用低到低于正常的选项来设置启动的命令/程序的优先级。似乎是最直接的解决方案。没有下载或脚本编写。其他解决方案可能适用于已经运行的 procs。
回答by Chris Miller
If you use PowerShell, you could write a script that let you change the priority of a process. I found the following PowerShell function on the Monad blog:
如果您使用PowerShell,您可以编写一个脚本来更改进程的优先级。我在Monad 博客上找到了以下 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)`""
}
From the PowerShell prompt, you would do something line:
在 PowerShell 提示符下,您将执行以下操作:
set-ProcessPriority SomeProcessName "High"
回答by ggasp
Maybe you want to consider using ProcessTamerthat "automatize" the process of downgrading or upgrading process priority based in your settings.
也许您想考虑使用ProcessTamer根据您的设置“自动化”降级或升级进程优先级的过程。
I've been using it for two years. It's very simple but really effective!
我已经使用它两年了。这很简单,但真的很有效!
回答by ggasp
from http://techtasks.com/code/viewbookcode/567
来自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";
}