nice 調整或給予程序的 nice 值。
renice 改變正執行中的程序之 nice 值。
[root@dywOffice ~]# ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 29849 29844 0 76 0 - 629 wait pts/2 00:00:00 su
4 S 0 29949 29849 0 75 0 - 784 wait pts/2 00:00:00 bash
0 R 0 26424 29949 0 76 0 - 556 - pts/2 00:00:00 ps
0 ~ 19
;
-20 ~ 19
;
[root@dywOffice ~]# nice --help
Usage: nice [OPTION] [COMMAND [ARG]...]
Run COMMAND with an adjusted scheduling priority.
With no COMMAND, print the current scheduling priority. ADJUST is 10
by default. Range goes from -20 (highest priority) to 19 (lowest).
-n, --adjustment=ADJUST increment priority by ADJUST first
--help display this help and exit
--version output version information and exit
Report bugs to <bug-coreutils@gnu.org>.
[root@dywOffice ~]# nice
0
[root@dywOffice ~]# nice -n -5 su
[root@dywOffice ~]# ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 29849 29844 0 76 0 - 629 wait pts/2 00:00:00 su
4 S 0 29949 29849 0 75 0 - 784 wait pts/2 00:00:00 bash
4 S 0 26449 29949 0 72 -5 - 629 wait pts/2 00:00:00 su
4 S 0 26452 26449 0 70 -5 - 732 wait pts/2 00:00:00 bash
0 R 0 26483 26452 0 71 -5 - 556 - pts/2 00:00:00 ps
[root@dywOffice ~]# exit
exit
[root@dywOffice ~]# ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 29849 29844 0 76 0 - 629 wait pts/2 00:00:00 su
4 S 0 29949 29849 0 75 0 - 784 wait pts/2 00:00:00 bash
0 R 0 26485 29949 0 76 0 - 555 - pts/2 00:00:00 ps
[root@dywOffice ~]# renice --help
usage: renice priority [ [ -p ] pids ] [ [ -g ] pgrps ] [ [ -u ] users ]
# -p :default
# 一般使用者
[dywang@dywHome2 ~]$ ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 500 5975 5942 0 75 0 - 837 wait pts/4 00:00:00 bash
0 R 500 6569 5975 0 76 0 - 560 - pts/4 00:00:00 ps
[dywang@dywHome2 ~]$ renice 10 -u dywang
500: old priority 0, new priority 10
[dywang@dywHome2 ~]$ bash
[dywang@dywHome2 ~]$ ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 500 5975 5942 0 85 10 - 837 wait pts/4 00:00:00 bash
0 S 500 6574 5975 0 85 10 - 836 wait pts/4 00:00:00 bash
0 R 500 6637 6574 0 86 10 - 560 - pts/4 00:00:00 ps
[dywang@dywHome2 ~]$ renice 5 -u dywang
500: old priority 10, new priority 5
[dywang@dywHome2 ~]$ ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 500 5975 5942 0 85 5 - 837 wait pts/4 00:00:00 bash
0 S 500 6574 5975 0 80 5 - 836 wait pts/4 00:00:00 bash
0 R 500 6649 6574 0 81 5 - 561 - pts/4 00:00:00 ps
[dywang@dywHome2 ~]$ renice -5 -u dywang
renice: 500: setpriority: Permission denied
[dywang@dywHome2 ~]$ renice 15 -p 6574
6574: old priority 5, new priority 15
[dywang@dywHome2 ~]$ ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 500 5975 5942 0 85 5 - 837 wait pts/4 00:00:00 bash
0 S 500 6574 5975 0 90 15 - 836 wait pts/4 00:00:00 bash
0 R 500 6655 6574 0 91 15 - 561 - pts/4 00:00:00 ps
# root 管理
[root@dywHome2 ~]# ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 5966 5942 0 85 5 - 639 wait pts/1 00:00:00 su
4 S 0 6383 5966 0 76 0 - 752 wait pts/1 00:00:00 bash
0 R 0 6661 6383 0 77 0 - 561 - pts/1 00:00:00 ps
[root@dywHome2 ~]# renice 0 -u dywang
500: old priority 5, new priority 0
[root@dywHome2 ~]# ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 5966 5942 0 80 0 - 639 wait pts/1 00:00:00 su
4 S 0 6383 5966 0 75 0 - 752 wait pts/1 00:00:00 bash
0 R 0 6734 6383 0 76 0 - 561 - pts/1 00:00:00 ps
[root@dywHome2 ~]# renice 10 6383
6383: old priority 0, new priority 10
[root@dywHome2 ~]# ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 5966 5942 0 80 0 - 639 wait pts/1 00:00:00 su
4 S 0 6383 5966 0 85 10 - 752 wait pts/1 00:00:00 bash
0 R 0 6738 6383 0 86 10 - 560 - pts/1 00:00:00 ps
[root@dywHome2 ~]# renice -10 6383
6383: old priority 10, new priority -10
[root@dywHome2 ~]# ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 5966 5942 0 80 0 - 639 wait pts/1 00:00:00 su
4 S 0 6383 5966 0 65 -10 - 752 wait pts/1 00:00:00 bash
0 R 0 6740 6383 0 66 -10 - 561 - pts/1 00:00:00 ps
練習題