Windows 中“nice”的等效词

发布于 2024-07-05 00:53:54 字数 137 浏览 8 评论 0原文

Windows 中是否有与 Unix 命令相当的命令,nice

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

我在谷歌上寻找这个的尝试被那些想不出更好形容词的人挫败了。

Is there a Windows equivalent of the Unix command, nice?

I'm specifically looking for something I can use at the command line, and not the "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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浮生面具三千个 2024-07-12 00:53:54

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

from 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";
}
青衫负雪 2024-07-12 00:53:54

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

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

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

If you want to set priority when launching a process you could use the built-in START command:

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.

如日中天 2024-07-12 00:53:54

如果您使用 PowerShell,您可以编写一个脚本来让您更改进程的优先级。 我在 Monad 博客< 上找到了以下 PowerShell 函数/a>:

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"

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:

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:

set-ProcessPriority SomeProcessName "High"
一袭水袖舞倾城 2024-07-12 00:53:54

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

我已经使用它两年了。 非常简单但是非常有效!

Maybe you want to consider using ProcessTamer that "automatize" the process of downgrading or upgrading process priority based in your settings.

I've been using it for two years. It's very simple but really effective!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文