Renice 命令

顾名思义, renice 是用来重新设置进程优先级的.

语法:

  1. renice [-2020的优先级] -p [PID]

降低一个进程的优先级

  1. $ ps axl | grep nice-test
  2. 0 509 13245 13216 30 10 5244 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh

然后:

  1. $ renice 16 -p 13245
  2. 13245: old priority 10, new priority 16
  3. $ ps axl | grep nice-test
  4. 0 509 13245 13216 36 16 5244 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh

优先级变成16了, 降低了.

增加一个进程的优先级

  1. $ ps axl | grep nice-test
  2. 0 509 13254 13216 30 10 4412 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh

然后增加它的优先级(以普通用户的身份):

  1. $ renice 5 -p 13254
  2. renice: 13254: setpriority: Permission denied
  3. Login as root to increase the priority of a running process

报错了, 说我们权限不足, 要用root才行.

  1. $ su -
  2. # renice 5 -p 13254
  3. 13254: old priority 10, new priority 5
  4. # ps axl | grep nice-test
  5. 0 509 13254 13216 25 5 4412 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh

这样就可以了.