[root@localhost ~] # nice [-n NI值] 命令
-n NI值:给命令赋予 NI 值,该值的范围为 -20~19;
[root@localhost ~]# service httpd start
[root@localhost ~]# ps -le 丨 grep "httd" | grep -v grep
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
1 S 0 2084 1 0 80 0 - 1130 - ? 00:00:00 httpd
5 S 2 2085 2084 0 80 0 - 1130 - ? 00:00:00 httpd
5 S 2 2086 2084 0 80 0 - 1130 - ? 00:00:00 httpd
5 S 2 2087 2084 0 80 0 - 1130 - ? 00:00:00 httpd
5 S 2 2088 2084 0 80 0 - 1130 - ? 00:00:00 httpd
5 S 2 2089 2084 0 80 0 - 1130 - ? 00:00:00 httpd
#用默认优先级自动apache服务,PRI值是80,而NI值是0
[root@localhost ~]# service httpd stop
#停止apache服务
[root@localhost ~]# nice -n -5 service httpd start
#启动apache服务,同时修改apache服务进程的NI值为-5
[rooteiocdlhost ~]# ps -le | grep "httpd" | grep -v grep
F S UID PID PPID C FRI NI ADDR SZ WCHAN TTY TIME CMD
1 S 0 2122 1 0 75 5 - 1130 - ? 00:00:00 httpd
5 S 2 2123 2122 0 75 5 - 1130 - ? 00:00:00 httpd
5 S 2 2124 2122 0 75 5 - 1130 - ? 00:00:00 httpd
5 S 2 2125 2122 0 75 5 - 1130 - ? 00:00:00 httpd
5 S 2 2126 2122 0 75 5 - 1130 - ? 00:00:00 httpd
5 S 2 2127 2122 0 75 5 - 1130 - ? 00:00:00 httpd
#httpd进程的PRI值变为了75,而NI值为-5
[root@localhost ~] # renice [优先级] PID
注意,此命令中使用的是进程的 PID 号,因此常与 ps 等命令配合使用。[root@localhost ~]# renice -10 2125 2125: old priority -5, new priority -10 [root@localhost ~]# ps -le | grep "httpd" | grep -v grep 1 S 0 2122 1 0 75 -5 - 113.0 - ? 00:00:00 httpd 5 S 2 2123 2122 0 75 -5 - 1130 - ? 00:00:00 httpd 5 S 2 2124 2122 0 75 -5 - 1130 - ? 00:00:00 httpd 5 S 2 2125 2122 0 70 -10 - 1130 - ? 00:00:00 httpd 5 S 2 2126 2122 0 75 -5 - 1130 - ? 00:00:00 httpd 5 S 2 2.127 2122 0 75 -5 - 1130 - ? 00:00:00 httpd #PID为2125的进程的PRI值为70,而NI值为-10如何合理地设置进程优先级,曾经是一件让系统管理员非常费神的事情。但现在已经不是了,如何地 CPU 足够强大,能够合理地对进程进行调整,输入输出设备也远远跟不上 CPU 地脚步,反而在更多的情况下,CPU 总是在等待哪些缓慢的 I/O(输入/输出)设备完成数据的读写和传输任务。
本文链接:http://task.lmcjl.com/news/11875.html