Windows相当于"不错"

Rya*_*Fox 68 unix windows process-management

是否有Windows平台上类似Unix命令的,漂亮的

我特意在命令行中查找可以使用的内容,而不是任务管理器中的"设置优先级"菜单.

我在谷歌上发现这种情况的尝试已被那些无法想出更好形容词的人所挫败.

Ste*_*cer 61

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

START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/WAIT] [/B] [command/program] [parameters]
Run Code Online (Sandbox Code Playgroud)

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

  • 为了使`start`表现得更像`nice`,使用`/ WAIT`和`/ B`选项使终端输出转到同一个窗口. (6认同)
  • 这仍然没有回答如何更改正在运行的进程的优先级 - duane(通过 VBScript)的答案目前是最好的答案。 (3认同)

Chr*_*ler 7

如果使用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)`""
}
Run Code Online (Sandbox Code Playgroud)

在PowerShell提示符下,您可以执行以下操作:

set-ProcessPriority SomeProcessName "High"
Run Code Online (Sandbox Code Playgroud)


gga*_*asp 5

也许您想考虑使用ProcessTamer来根据您的设置“自动”执行降级或升级过程优先级的过程。

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


小智 5

来自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";
}
Run Code Online (Sandbox Code Playgroud)