Windows等效的" nice"

时间:2020-03-05 18:38:12  来源:igfitidea点击:

Windows是否有与Unix命令等效的Windows,好吗?

我专门在寻找可以在命令行中使用的内容,而不是任务管理器中的"设置优先级"菜单。

那些无法提出更好形容词的人挫败了我在Google上发现此内容的尝试。

解决方案

回答

PrcView似乎也可以在命令行下运行:

http://www.teamcti.com/pview/prcview.htm

(检查-ph参数)

回答

也许我们想考虑使用ProcessTamer来根据设置"自动"执行降级或者升级过程优先级的过程。

我已经使用了两年了。这很简单,但确实有效!

回答

如果使用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)`""
}

在PowerShell提示符下,我们需要执行以下操作:

set-ProcessPriority SomeProcessName "High"

回答

如果要在启动进程时设置优先级,则可以使用内置的start命令:

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

使用低至低于正常的选项来设置启动的命令/程序的优先级。似乎是最直接的解决方案。没有下载或者脚本编写。其他解决方案可能适用于已经运行的proc。

回答

来自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";
}