nice和renice命令

蒲德曜
2023-12-01

nice:进程开始前调整优先级
renice:进程进行中调整优先级
其中,nice命令默认对进程的nice值加10,从而降低该进程的优先级。

查看进程情况:

lyg@ubuntu:~$ ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S  1000 13950 13941  0  80   0 -  6724 wait   pts/1    00:00:00 bash
0 R  1000 14206 13950  0  80   0 -  3553 -      pts/1    00:00:00 ps

后台运行一个任务:

lyg@ubuntu:~$ nice -n 5 vi &
[1] 14265

查看进程:

lyg@ubuntu:~$ ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S  1000 13950 13941  0  80   0 -  6724 wait   pts/1    00:00:00 bash
0 T  1000 14265 13950  0  85   5 -  6290 signal pts/1    00:00:00 vi
0 R  1000 14266 13950  0  80   0 -  3553 -      pts/1    00:00:00 ps

[1]+  Stopped                 nice -n 5 vi

对进行中的进程调整nice值:

lyg@ubuntu:~$ renice 15 14265
14265 (process ID) old priority 5, new priority 15

查看进程:

lyg@ubuntu:~$ ps -l
F S   UID   PID  PPID  C PRI  **NI** ADDR SZ WCHAN  TTY          TIME CMD
0 S  1000 13950 13941  0  80   0 -  6724 wait   pts/1    00:00:00 bash
0 T  1000 14265 13950  0  95  15 -  6290 signal pts/1    00:00:00 vi
0 R  1000 14272 13950  0  80   0 -  3553 -      pts/1    00:00:00 ps

杀死任务:

lyg@ubuntu:~$ kill -9 %1

[1]+  Stopped                 nice -n 5 vi
lyg@ubuntu:~$ ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S  1000 13950 13941  0  80   0 -  6724 wait   pts/1    00:00:00 bash
0 R  1000 14329 13950  0  80   0 -  3553 -      pts/1    00:00:00 ps
[1]+  Killed                  nice -n 5 vi

任务可用jobs命令列出

 类似资料: