网上查了很多都说得模棱两可。
结合http://blog.csdn.net/thinkerabc/article/details/656236,然后自己实践了一下,记一下
1.进入tty,直接nice一下:
ubuntu14043@ubuntu14043:~$ ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 1000 2079 2078 0 80 0 - 6712 wait pts/5 00:00:00 bash
0 R 1000 2123 2079 0 80 0 - 3554 - pts/5 00:00:00 ps
ubuntu14043@ubuntu14043:~$ nice
0
ubuntu14043@ubuntu14043:~$ ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 1000 2079 2078 0 80 0 - 6712 wait pts/5 00:00:00 bash
0 R 1000 2174 2079 0 80 0 - 3554 - pts/5 00:00:00 ps
猜测没有参数的nice结果显示的是默认进程bash的NI值
2.
ubuntu14043@ubuntu14043:~$ nice ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 1000 2079 2078 0 80 0 - 6712 wait pts/5 00:00:00 bash
0 R 1000 2182 2079 0 90 10 - 3554 - pts/5 00:00:00 ps
ubuntu14043@ubuntu14043:~$ nice
0
按照引用blog说的,ps的优先级将在原有基础上降低10,NI值变为10,看来nice值确实会在改变NI的同时改变PRI.
猜测不带参数的nice命令依然显示的是bash的NI
3.
ubuntu14043@ubuntu14043:~$ nice bash
ubuntu14043@ubuntu14043:~$ nice
10
ubuntu14043@ubuntu14043:~$ ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 1000 2079 2078 0 80 0 - 6712 wait pts/5 00:00:00 bash
0 S 1000 2222 2079 0 90 10 - 6718 wait pts/5 00:00:00 bash
0 R 1000 2235 2222 0 90 10 - 3554 - pts/5 00:00:00 ps
把bash nice一次,再执行不带参数的nice进程,显示结果10.接下来的ps显示多了一个NI值为10的进程。
进一步猜测不带参数的nice显示的是默认的bash的NI
4.
0 R 1000 2245 2222 0 90 10 - 3554 - pts/5 00:00:00 ps
ubuntu14043@ubuntu14043:~$ kill -9 2222
Killed
ubuntu14043@ubuntu14043:~$ ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 1000 2079 2078 0 80 0 - 6712 wait pts/5 00:00:00 bash
0 R 1000 2246 2079 0 80 0 - 3554 - pts/5 00:00:00 ps
ubuntu14043@ubuntu14043:~$
ubuntu14043@ubuntu14043:~$ nice
0
干掉了新建的bash进程,然后nice不带参数,结果是10
以上验证了不带参数显示的是默认bash的NI。nice会产生三个结果:改变进程的PRI,改变进程的NI,运行进程
来源:CSDN
作者:a_big_pig
链接:https://blog.csdn.net/a_big_pig/article/details/49620779