..........................................................................................................................................................
..........................................................................................................................................................
4.1.3.4 进程优先级:nice
..........................................................................................................................................................
nice以更改过的优先序来执行程序,如果未指定程序,则会印出目前的排程优先序,内定的 adjustment 为 10,范围为 -20(最高优先序)到 19(最低优先序)。 使用权限:所有使用者。
..........................................................................................................................................................
nice值越大:表示优先级越低 nice值越小:表示优先级越高
..........................................................................................................................................................
系统中的两种优先级(top命令可以查看):
..........................................................................................................................................................
NI:实际nice值 PR(+20):将nice级别显示为映射到更大的优先级队列,-20映射到0,+10映射到39
..........................................................................................................................................................
nice
命令的基本语法如下:
nice [-n adjustment] [-adjustment] [--adjustment=adjustment] [command [arg...]]
..........................................................................................................................................................
参数说明:
-
-n adjustment, -adjustment, --adjustment=adjustment 皆为将该原有优先序的增加 adjustment
..........................................................................................................................................................
例:
查看进程优先级
ps axo pid,command,nice --sort=nice
查看系统优先级
# PRI top -d 1 -p pid1,pid2,pid3 #(以下例子中6000/7000/8000的pid)
手动启动具有不用nice级别的进程
# 启动进程时,通常会继承父进程的nice级别,默认为0。 sleep 5 sleep 6000 & # &为后台执行 # 调整进程优先级 ps axo pid,command,nice | grep sleep nice -n -5 sleep 7000 & # 创建进程时添加优先级 ps axo pid,command,nice | grep sleep # 再次查看调整后的优先级 sleep 8000 & # 手动更改已存在进程的优先级 renice -20 pid ps axo pid,command,nice | grep sleep
将ls的优先序加 1 并执行
nice -n 1 ls
将ls的优先序加 1 并执行
nice ls