The Shell command is the most common use: nice [-n <Priority>] [execute instructions], wherein the priority range from -20-19, wherein -20 maximum, 19 minimum, only the system administrator can set negative level. `` `???
#后台执行sleep 100 秒,同时在启动时将其nice值置为19
[ root@xieqichao ~ ] # nice - n 19 sleep 100 &
[ 1 ] 4661
#后台执行sleep 100 秒,同时在启动时将其nice值置为- 19
[ root@xieqichao ~ ] # nice - n - 19 sleep 100 &
[ 2 ] 4664
#关注ps - l输出中用黄色高亮的两行,它们的NI 值和我们执行是设置的值一致。
[ root@xieqichao ~ ] # ps - l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 2833 2829 0 80 0 - 1739 - pts/ 2 00 : 00 : 00 bash
0 S 0 4661 2833 0 99 19 - 1066 - pts/ 2 00 : 00 : 00 sleep
4 S 0 4664 2833 0 61 - 19 - 1066 - pts/ 2 00 : 00 : 00 sleep
4 R 0 4665 2833 1 80 0 - 1231 - pts/ 2 00 : 00 : 00 ps
renice command is used to reset nice value for the process has been carried out, the order contains several of the following common options:
Options
Explanation
-g
Using the program group name, modify the priority of all programs belonging to the group of programs.
-p
Changing the priority level of the program, this parameter is a preset value.
-u
Specify the user name, all belonging to modify the priority of the user program.
#切换到stephen用户下执行一个后台进程,这里sleep进程将在后台睡眠1000 秒。
[ root@xieqichao ~ ] # su stephen
[ root@xieqichao ~ ] # sleep 1000 &
[ 1 ] 4812
[ root@xieqichao ~ ] # exit #退回到切换前的root用户
#查看已经启动的后台sleep进程,其ni值为0 ,宿主用户为stephen
[ root@xieqichao ~ ] # ps - eo user, pid, ni, command | grep stephen
stephen 4812 0 sleep 1000
root 4821 0 grep stephen
#以指定用户的方式修改该用户下所有进程的nice值
[ root@xieqichao ~ ] # renice - n 5 - u stephen
500 : old priority 0 , new priority 5
#从再次执行ps的输出结果可以看出,该sleep后台进程的nice值已经调成了5
[ root@xieqichao ~ ] # ps - eo user, pid, ni, command | grep stephen
stephen 4812 5 sleep 1000
root 4826 0 grep stephen
#以指定进程pid的方式修改该进程的nice值
[ root@xieqichao ~ ] # renice - n 10 - p 4812
4812 : old priority 5 , new priority 10
#再次执行ps,该sleep后台进程的nice值已经从5 变成了10
[ root@xieqichao ~ ] # ps - eo user, pid, ni, command | grep stephen
stephen 4812 10 sleep 1000
root 4829 0 grep stephen