• 要找福利?记不住网址?搜不到?如何与我们保持联系?试试 CTRL+D 把零点博客添加进您的浏览器收藏夹,一键直达永不失联!

系统管理-Linux nice命令

linux系统 涛涛 166次浏览 0个评论

Linux nice命令

Linux 命令大全 Linux 命令大全

Linux nice命令以更改过的优先序来执行程序,如果未指定程序,则会印出目前的排程优先序,内定的 adjustment 为 10,范围为 -20(最高优先序)到 19(最低优先序)。

使用权限:所有使用者。

语法

<span class="pln">nice </span><span class="pun">[-</span><span class="pln">n adjustment</span><span class="pun">]</span> <span class="pun">[-</span><span class="pln">adjustment</span><span class="pun">]</span> <span class="pun">[--</span><span class="pln">adjustment</span><span class="pun">=</span><span class="pln">adjustment</span><span class="pun">]</span> <span class="pun">[--</span><span class="pln">help</span><span class="pun">]</span> <span class="pun">[--</span><span class="pln">version</span><span class="pun">]</span> <span class="pun">[</span><span class="pln">command </span><span class="pun">[</span><span class="pln">arg</span><span class="pun">...]]</span>

参数说明

  • -n adjustment, -adjustment, –adjustment=adjustment 皆为将该原有优先序的增加 adjustment
  • –help 显示求助讯息
  • –version 显示版本资讯

实例

设置程序运行时的优先级

<span class="com"># vi & //后台运行</span>
<span class="pun">[</span><span class="lit">1</span><span class="pun">]</span> <span class="lit">15297</span>
<span class="com"># nice vi & //设置默认优先级</span>
<span class="pun">[</span><span class="lit">2</span><span class="pun">]</span> <span class="lit">15298</span>

<span class="pun">[</span><span class="lit">1</span><span class="pun">]+</span> <span class="typ">Stopped</span><span class="pln">         vi
</span><span class="com"># nice -n 19 vi & //设置优先级为19</span>
<span class="pun">[</span><span class="lit">3</span><span class="pun">]</span> <span class="lit">15299</span>

<span class="pun">[</span><span class="lit">2</span><span class="pun">]+</span> <span class="typ">Stopped</span><span class="pln">         nice vi
</span><span class="com"># nice -n -20 vi & //设置优先级为 -20</span>
<span class="pun">[</span><span class="lit">4</span><span class="pun">]</span> <span class="lit">15300</span>

<span class="pun">[</span><span class="lit">3</span><span class="pun">]+</span> <span class="typ">Stopped</span><span class="pln">         nice </span><span class="pun">-</span><span class="pln">n </span><span class="lit">19</span><span class="pln"> vi
</span><span class="com"># ps -l //显示进程</span><span class="pln">
F S  UID  PID PPID C PRI NI ADDR SZ WCHAN TTY     TIME CMD
</span><span class="lit">4</span><span class="pln"> S   </span><span class="lit">0</span> <span class="lit">15278</span> <span class="lit">15212</span> <span class="lit">0</span> <span class="lit">80</span>  <span class="lit">0</span> <span class="pun">-</span> <span class="lit">1208</span><span class="pln"> wait  pts</span><span class="pun">/</span><span class="lit">2</span>  <span class="lit">00</span><span class="pun">:</span><span class="lit">00</span><span class="pun">:</span><span class="lit">00</span><span class="pln"> bash
</span><span class="lit">0</span><span class="pln"> T   </span><span class="lit">0</span> <span class="lit">15297</span> <span class="lit">15278</span> <span class="lit">0</span> <span class="lit">80</span>  <span class="lit">0</span> <span class="pun">-</span> <span class="lit">2687</span><span class="pln"> signal pts</span><span class="pun">/</span><span class="lit">2</span>  <span class="lit">00</span><span class="pun">:</span><span class="lit">00</span><span class="pun">:</span><span class="lit">00</span><span class="pln"> vi
</span><span class="lit">0</span><span class="pln"> T   </span><span class="lit">0</span> <span class="lit">15298</span> <span class="lit">15278</span> <span class="lit">0</span> <span class="lit">90</span> <span class="lit">10</span> <span class="pun">-</span> <span class="lit">2687</span><span class="pln"> signal pts</span><span class="pun">/</span><span class="lit">2</span>  <span class="lit">00</span><span class="pun">:</span><span class="lit">00</span><span class="pun">:</span><span class="lit">00</span><span class="pln"> vi
</span><span class="lit">0</span><span class="pln"> T   </span><span class="lit">0</span> <span class="lit">15299</span> <span class="lit">15278</span> <span class="lit">1</span> <span class="lit">99</span> <span class="lit">19</span> <span class="pun">-</span> <span class="lit">2687</span><span class="pln"> signal pts</span><span class="pun">/</span><span class="lit">2</span>  <span class="lit">00</span><span class="pun">:</span><span class="lit">00</span><span class="pun">:</span><span class="lit">00</span><span class="pln"> vi
</span><span class="lit">4</span><span class="pln"> T   </span><span class="lit">0</span> <span class="lit">15300</span> <span class="lit">15278</span> <span class="lit">3</span> <span class="lit">60</span> <span class="pun">-</span><span class="lit">20</span> <span class="pun">-</span> <span class="lit">2687</span><span class="pln"> signal pts</span><span class="pun">/</span><span class="lit">2</span>  <span class="lit">00</span><span class="pun">:</span><span class="lit">00</span><span class="pun">:</span><span class="lit">00</span><span class="pln"> vi
</span><span class="lit">4</span><span class="pln"> R   </span><span class="lit">0</span> <span class="lit">15301</span> <span class="lit">15278</span> <span class="lit">0</span> <span class="lit">80</span>  <span class="lit">0</span> <span class="pun">-</span>  <span class="lit">625</span> <span class="pun">-</span><span class="pln">   pts</span><span class="pun">/</span><span class="lit">2</span>  <span class="lit">00</span><span class="pun">:</span><span class="lit">00</span><span class="pun">:</span><span class="lit">00</span><span class="pln"> ps

</span><span class="pun">[</span><span class="lit">4</span><span class="pun">]+</span> <span class="typ">Stopped</span><span class="pln">         nice </span><span class="pun">-</span><span class="pln">n </span><span class="pun">-</span><span class="lit">20</span><span class="pln"> vi</span>

将 ls 的优先序加 1 并执行

<span class="pln">nice </span><span class="pun">-</span><span class="pln">n </span><span class="lit">1</span><span class="pln"> ls</span>

将 ls 的优先序加 10 并执行

<span class="pln">nice ls</span>

注意:优先序 (priority) 为操作系统用来决定 CPU 分配的参数,Linux 使用『回合制(round-robin)』的演算法来做 CPU 排程,优先序越高,所可能获得的 CPU时间就越多。


欢迎转载本文:系统管理-Linux nice命令
喜欢 (0)
[ld]
分享 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址