1. Linux top命令输出中PR值和NI值有什么不同
NI 是优先值,是用户层面的概念, PR是进程的实际优先级, 是给内核(kernel)看(用)的。
一般情况下,PR=NI+20, 如果一个进程的优先级PR是20, 那么它的NI(nice)值就是20-20=0。
可以通过改变NI来改变PR: PRI(new) = PRI(old) + nice
NI is the nice value, which is a user-space concept. PR is the process's actual priority, as viewed by the Linux kernel.
For normal processes, the kernel priority is simply +20 from the nice value. Thus a process with the neutral nice value of zero has a kernel priority of 20. This offset-by-20 is done so that a process with a nice value of -20, the highest priority nice value,
receives a kernel priority of zero. Lower numeric values equal higher scheduling priority.
For realtime processes, the kernel priority is the process's real-time priority, but thePR column will simply print RT.
In some versions of the Linux kernel, the kernel priority could differ from the nice value, as the process scheduler applied a small bonus or punishment to interactive or processor-hogging tasks, respectively. In these older kernels, the value given by the
PR column could differ from the nice value. This isn't true with the kernel's current scheduler, the Completely Fair Scheduler (CFS).
This article come from:
http://www.quora.com/Linux/What-is-the-difference-between-the-NI-and-PR-values-in-the-top-1-commands-output
2. Nice调整限制:
nice 值可调整的范围为 -20 ~ 19 ;
Useful priorities are: 20 (the affected processes will run only when nothing else
in the system wants to), 0 (the ''base'' scheduling priority), anything negative (to make things go very fast).
root 可随意调整自己或他人程序的 Nice 值,且范围为 -20 ~ 19 ;
一般使用者仅可调整自己程序的 Nice 值,且范围仅为 0 ~ 19 (避免一般用户抢占系统资源);
一般使用者仅可将 nice 值越调越高,例如本来 nice 为 5 ,则未来仅能调整到大于 5;
3. Nice调整方法
3.1新执行的指令即给予新的 nice 值
[root@www ~]# nice [-n 数字] command
选项与参数:
-n :后面接一个数值,数值的范围 -20 ~ 19。
www.2cto.com
用ps -l查的话,里面显示的PRI就是PRI(new),核心会自动调整,不是PRI(old) + nice的值,会调高一点点
3.2 已存在程序的 nice 重新调整
renice [number] PID
4. 设置某用户的所有进程优先级
修改/etc/security/limits.conf, 增加一行
userxxx - nice 19
要使 limits.conf 文件配置生效,必须要确保 pam_limits.so 文件被加入到启动文件中。查看 /etc/pam.d/login 文件中有:
session required /lib/security/pam_limits.so
5. 其他:
5.1用taskset限制进程的CPU使用率:
http://www.cyberciti.biz/tips/setting-processor-affinity-certain-task-or-process.html
http://www.jb51.net/LINUXjishu/97275.html
5.2采用cpulimit限制进程的CPU使用率(发生SIGSTOP和SIGCONT信号):
http://cpulimit.sourceforge.net/
http://www.ttlsa.com/tools/cpulimit-limit-cpu-usage-on-linux/
http://maxmanii.blog.163.com/blog/static/1200622672009517112429702/