文章目录
- 16. 进程管理和作业调度
- 16.1 进程概述
- 16.2 进程查看 - BSD
- 16.3 进程状态
- 16.4 进程查看 - System-v-Unix
- 16.5 进程查看 - linux
- 16.6 进程动态查看
- 16.7 进程关闭
- 16.8 作业调度 - 前后台管理
- 16.9 守护进程 - deamon
- 16.10 进程优先级调整
16. 进程管理和作业调度
16.1 进程概述
$# 1.
Linux中不允许进程跨越边界去访问其他进程的代码、数据,这是操作系统保护模式的核心内容。 进程间往往需要协同工作,交互信息,如何既不破坏进程保护,又能实现进程间通信的合理要求?
两套机制:- 管道机制
- 信号机制进程: 进行中的程序
程序和进程之间的关系
程序 ------ 静态 (程序员所书写的代码) --- 存储在硬盘中,没有被加载到内存中
进程 ------ 动态 (运行了程序 - 进行中的程序), 程序被加载进入到了内存进程区分前台和后台1. 进程查看
2. 终止进程
3. 进程前台后台调度
16.2 进程查看 - BSD
$# 1.
1. 判断系统中运行进程数量
2. 判断服务器运行健康状态
ps BSD Unix用法
ps system-v 用法
ps linux / GNU 用法ps (process show) - Unix ( -> AT&A System-v | BSD) 苹果a = 显示所有前台进程x = 显示所有没有控制终端的后台进程u = 以进程产生的格式显示运行状态
[zy@localhost ~]$ ps au
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
zy 1738 0.0 0.1 116176 2860 pts/0 Ss 15:20 0:00 -bash
zy 2518 0.0 0.0 151064 1808 pts/0 R+ 16:31 0:00 ps au
[zy@localhost ~]$
[zy@localhost ~]$ ps aux | tail -n 3
root 2527 0.0 0.0 107904 348 ? S 16:32 0:00 sleep 60
zy 2532 0.0 0.0 151064 1808 pts/0 R+ 16:32 0:00 ps aux
zy 2533 0.0 0.0 107940 668 pts/0 R+ 16:32 0:00 tail -n 3
[zy@localhost ~]$
[zy@localhost ~]$ ps aux | wc -l
148
[zy@localhost ~]$
$# 2. BSD的详细信息
[zy@localhost ~]$ ps aux | head
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.3 128096 6688 ? Ss 15:14 0:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 21zy 2833 0.0 0.0 151064 1808 pts/0 R+ 16:59 0:00 ps aux
[zy@localhost ~]$ USER 改进程的所有者
PID 进程ID process ID
%CPU 物理CPU百分比利用率
%MEM 物理内存百分比利用率
VSZ Virtualmenory Size 虚拟内存大小 - 使用量 (KB)
RSS 固定驻留物理内存量
TTY 该进程所在的终端 (? 该进程直接通过内核产生,不是通过终端方式产生)
STAT 进程状态 (R/S/D/T/Z)重要
STATT 该进程启动时间
TIME 该进程占用CPU时间分片
COMMAND 产生该进程时所使用的命令
16.3 进程状态
$# 3. 进程
父进程子进程
process state codes
R 该进程正在CPU上执行,或者正在等待执行
T 进程被暂停,该进程可以通过接受内核发送信号继续恢复执行
Z 僵尸进程,父进程关闭后,子进程没有自动关闭
X 僵尸进程被父进程正常关闭彻底释放。 僵尸进程正常退出
s(小) 领导者进程,该进程下包含了子进程
< 高优先级进程
N 低优先级进程
+ 该进程位于后台
l(小) 该进程包含了多个线程
S 普通睡眠(sleeping),可以被唤醒
K 该进程如果处于任务等待中时,可以被唤醒
D 不可中断的睡眠内存,不可以被唤醒
I D - 子状态,内核不去统计I状态的负载均衡值
[zy@localhost ~]$ ps -aux | tail -n 2
zy 3315 0.0 0.0 153148 1852 pts/0 R+ 17:43 0:00 ps -aux
zy 3316 0.0 0.0 107940 668 pts/0 R+ 17:43 0:00 tail -n 2
[zy@localhost ~]$
[zy@localhost ~]$ ps -aux | grep "3448"
root 3448 0.0 0.1 220572 3392 pts/1 S 17:47 0:00 su zy04
zy04 3449 0.1 0.1 116164 2852 pts/1 S+ 17:47 0:00 bash
[root@localhost ~]
[root@localhost ~]
root 3448 0.0 0.1 220572 3392 pts/1 T 17:47 0:00 su zy04
[root@localhost ~][root@localhost ~]
[root@localhost ~]
root 3448 0.0 0.1 220572 3392 pts/1 S 17:47 0:00 su zy04
[root@localhost ~]
16.4 进程查看 - System-v-Unix
$# 1.
ps -ef
-e 查看所有进程
-f 全部信息输出(full)
[root@localhost ~]PID TTY TIME CMD
[root@localhost ~][root@localhost ~]
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 15:14 ? 00:00:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
root 2 0 0 15:14 ? 00:00:00 [kthreadd]
[root@localhost ~]
PID为0的进程为系统内核进程(命令看不到)
在linux中运行的第一个进程是systemd,它拉活了[kthreadd]
[kthreadd] 线程任务组,通过它拉活其他进程UID 进程所有者名称
PID 进程ID
PPID 表示当前进程的父ID
C 物理CPU百分比利用率
STIME 该进程启动时间
TTY 该进程所在的终端 (? 该进程直接通过内核产生,不是通过终端方式产生)
TIME 该进程占用CPU时间分片
CMD 产生该进程时所使用的命令
$# 2.
eg: 父进程子进程线程
[zy@localhost ~]$
[zy@localhost ~]$ firefox
[root@localhost ~]
zy 5913 5906 0 18:53 pts/0 00:00:00 bash
zy 6023 5913 1 18:56 pts/0 00:00:03 /usr/lib64/firefox/firefox
[root@localhost ~]
[root@localhost ~]
zy 6023 5913 1 18:56 pts/0 00:00:03 /usr/lib64/firefox/firefox
zy 6093 6023 0 18:56 ? 00:00:00 /usr/lib64/firefox/plugin-container -greomni /usr/lib64/firefox/omni.ja -appomni /usr/lib64/firefox/browser/omni.ja -appdir /usr/lib64/firefox/browser 6023 tab
[root@localhost ~]
[root@localhost ~]
zy 6023 1.6 10.5 2163872 196460 pts/0 Sl+ 18:56 0:12 /usr/lib64/firefox/firefox
zy 6093 0.2 5.1 1777032 95192 ? Sl 18:56 0:01 /usr/lib64/firefox/plugin-container -greomni /usr/lib64/firefox/omni.ja -appomni /usr/lib64/firefox/browser/omni.ja -appdir /usr/lib64/firefox/browser 6023 tab
[root@localhost ~]
[root@localhost ~]
Thread 2 (Thread 0x7f0b2b0fe700 (LWP 6931)):
Thread 1 (Thread 0x7f0b67f08740 (LWP 6023)):
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
16.5 进程查看 - linux
$# 1.
ps -le
-e 查看所有进程
-l 全部信息以长格式输出
[zy@localhost ~]$ ps -le | head -n 5
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 1 0 0 80 0 - 48408 ep_pol ? 00:00:02 systemd
1 S 0 2 0 0 80 0 - 0 kthrea ? 00:00:00 kthreadd
1 S 0 4 2 0 60 -20 - 0 worker ? 00:00:00 kworker/0:0H
1 S 0 6 2 0 80 0 - 0 smpboo ? 00:00:00 ksoftirqd/0
[zy@localhost ~]$ $# 2. 详细信息
F 内核为进程分配到的标记
S 进程的状态
UID 进程拥有者UID
PID 进程ID
PPID 表示当前进程的父进程ID
C 物理CPU百分比利用率PRI * 进程优先级,数值越小-优先级越高,进程优先执行
NI * Nice 调整进程优先级的修正量,通过该参数决定进程优先级ADDR 进程的内存地址
SZ 假如该进程需要进行swap交换,需要多大的交换空间-KB
WCHAN 该进程在进入到睡眠状态下所使用函数TTY 该进程所在的终端 (? 该进程直接通过内核产生,不是通过终端方式产生)
TIME 该进程占用CPU时间分片
CMD 产生该进程时所使用的命令
$# 3. 总结
ps aux
ps -ef
ps -le
pstack
pstree
16.6 进程动态查看
$# 1.top
默认每3秒更新一次
每敲一次回车更新一次
q 表示退出查看
[zy@localhost ~]$ top -d 1 $# 2. 详细信息
$ 2.1 第一行
top - 19:56:17 up 4:42, 4 users, load average: 0.00, 0.01, 0.0519:56:17 当前系统时间
up 4:42 从系统从开机,到当前的使用时间
4 users 表示当前登录到系统的用户数量
load average: 0.00, 0.01, 0.05 系统负载平均值(CPU: 最后1分钟:最后5分钟:最后15分钟)
$ 2.2 第二行
Tasks: 190 total, 1 running, 189 sleeping, 0 stopped, 0 zombie190 total 系统当前总进程数量
1 running 系统当前真正运行的进程数量
189 sleeping 系统中睡眠状态的进程数量
0 stopped 处于暂停状态下的进程数量
0 zombie 僵尸进程数量
$ 2.3 第三行
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st0.0 us 用户态进程占用CPU百分比
0.0 sy 内核态进程占用CPU百分比
0.0 ni 用户态进程通过nice进行优先级修正的百分比
100.0 id 当前CPU空闲百分比
0.0 wa 进程等待进行I/O所占的百分比
0.0 hi 硬件中断请求百分比
0.0 si 软件中断请求百分比
0.0 st hypervisor管理程序从虚拟机窃取时间的百分比
$ 2.4 第四行
KiB Mem : 1862820 total, 277516 free, 958648 used, 626656 buff/cache1862820 total 物理总内存数量
277516 free 闲置物理内存数量
958648 used 已经使用的内存数量
626656 buff/cache 内存缓冲区 (和硬盘进行数据交互)
物理总内存数量 = 闲置物理内存数量 + 已经使用的内存数量 + 内存缓冲区
[zy@localhost ~]$ free -mtotal used free shared buff/cache available
Mem: 1819 938 266 29 614 633
Swap: 2047 0 2047
[zy@localhost ~]$
$ 2.5 第五行
KiB Swap: 2097148 total, 2097148 free, 0 used. 650640 avail Mem Swap 内存交换分区 -- 位于硬盘上的一个分区2097148 total 总内存交换分区大小
2097148 free 闲置内存交换分区大小
0 used. 使用的内存交换分区的大小
650640 avail Mem 启动新的应用程序估计可以使用的物理内存大小总内存交换分区大小 = 闲置内存交换分区大小 + 使用的内存交换分区的大小
$ 2.6 第六行
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 193632 6708 4084 S 0.0 0.4 0:02.60 systemd PID 进程ID
USER 进程的用户
PR 进程优先级
NI NICE值
VIRT 虚拟内存使用的大小
RES 固定驻留物理内存大小
SHR 共享内存的大小
S 进程状态
%CPU 该进程的物理CPU百分比
%MEM 该进程的物理内存百分比
TIME+ 使用CPU时间的累计
COMMAND 产生该进程使用的命令
$# 3. 实战
P 按照CPU使用量排序
M 按照内存使用量排序
N 按照进程ID排序
16.7 进程关闭
$# 1. kill
kill [-singal] [进程ID][root@localhost ~][root@localhost ~]
zy 4660 4199 0 18:40 ? 00:00:01 /usr/bin/gnome-software --gapplication-service
root 8782 5799 15 21:37 pts/1 00:00:07 cat /dev/zero
root 8792 8733 0 21:38 pts/2 00:00:00 grep --color=auto -i cat
[root@localhost ~]
[root@localhost ~][root@localhost ~]
Terminated
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
======================================================================================$# 2. singal
[root@localhost ~]1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
[root@localhost ~]15) SIGTERM -> 正常关闭
9) SIGKILL -> 强制关闭
1) SIGHUP -> 重启进程(重新运行子进程)
18) SIGCONT -> 恢复进程
19) SIGSTOP -> 暂停进程[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~][root@localhost ~]$# 3. 实战
[root@localhost Desktop]
[root@localhost Desktop]
[root@localhost Desktop]
zy
zy1
~
[root@localhost Desktop]
[root@localhost ~]
root 9041 0.2 0.2 151252 4976 pts/1 S+ 21:58 0:00 vim 123.txt
[root@localhost ~]
[root@localhost Desktop]
Vim: Caught deadly signal TERMVim: Finished.
Terminated
[root@localhost Desktop]
zy
[root@localhost Desktop]
123.txt
.123.txt.swap[root@localhost Desktop]
. .. 123.txt .123.txt.swp
[root@localhost Desktop]
zy
[root@localhost Desktop]
U3210
[root@localhost Desktop]
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort: R
[root@localhost Desktop]
zy
zy01
[root@localhost Desktop]
[root@localhost ~]
[root@localhost ~][root@localhost Desktop]1 Killed:
[root@localhost Desktop]
[root@localhost Desktop]17 games:::18 tape:::19 video:::20 ftp:::21 lock:::22 audio:::23 nobody:::24 users:::
:set number
======================================================================================总结: 如果一个进程无法正常关闭掉,再进行使用强制关闭。否则可能会导致进程再次拉活时出现异常,数据丢失问题。
======================================================================================$# 4. 通过进程名称,对进程进行操作
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~][root@localhost ~]
root pts/1 2023-02-04 18:51 (192.168.8.1)
zy :0 2023-02-04 18:40 (:0)
zy pts/0 2023-02-04 18:53 (:0)
zy pts/2 2023-02-04 22:35 (192.168.8.1)
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
root pts/1 2023-02-04 18:51 (192.168.8.1)
zy :0 2023-02-04 18:40 (:0)
[root@localhost ~]
16.8 作业调度 - 前后台管理
$# 1.
[zy@localhost ~]$ cat /dev/zero
^Z
[1]+ Stopped cat /dev/zero
[zy@localhost ~]$ frontend-ground -fg
backend-ground -bg[zy@localhost ~]$ jobs
[1]+ Stopped cat /dev/zero
[zy@localhost ~]$ [root@localhost ~]
[root@localhost ~][zy@localhost ~]$ bg %1
[1]+ cat /dev/zero &
[zy@localhost ~]$
[zy@localhost ~]$ fg %1
cat /dev/zero$# 2. 实战
18) SIGCONT -> 恢复进程
19) SIGSTOP -> 暂停进程
[zy@localhost ~]$ firefox
^Z
[1]+ Stopped firefox
[zy@localhost ~]$ jobs
[1]+ Stopped firefox
[zy@localhost ~]$ kill -18 %1
[zy@localhost ~]$
[zy@localhost ~]$ jobs
[1]+ Running firefox &
[zy@localhost ~]$
[zy@localhost ~]$ kill -19 %1
[1]+ Stopped firefox
[zy@localhost ~]$
======================================================================================$# 3. 前后台调度实战
[root@localhost ~]
[1]- Stopped cat /dev/zero
[2]+ Stopped cat /dev/zero >> /dev/null
[root@localhost ~]
[1]- cat /dev/zero &
[root@localhost ~]
[1]- Running cat /dev/zero &
[2]+ Stopped cat /dev/zero >> /dev/null
[root@localhost ~]
[root@localhost ~][root@localhost ~]
[root@localhost ~]
[1]- Killed cat /dev/zero[2]+ Stopped cat /dev/zero >> /dev/null
[root@localhost ~]
[2]+ Killed cat /dev/zero >> /dev/null
[root@localhost ~]
[root@localhost ~]$# 4. 创建对应的进程时,直接在后台运行
[zy@localhost ~]$ firefox &
[1] 11179
[zy@localhost ~]$
[zy@localhost ~]$ pstree -ap | grep -i "firefox"| | |-firefox,11179| | | |-{firefox},11203| | | |-{firefox},11296| | | `-{firefox},11297| | |-grep,11375 --color=auto -i firefox
[zy@localhost ~]$ [root@localhost ~]
[1] 11315
[root@localhost ~]
[root@localhost ~]| | | |-gnome-software,4660 --gapplication-service| | |-cat,11315 /dev/zero| | |-grep,11335 --color=auto -i cat| |-cat,10011 /dev/zero| `-cat,10923 /dev/zero
[root@localhost ~]
[zy@localhost ~]$ firefox &
[1] 12396
[zy@localhost ~]$
[zy@localhost ~]$ jobs
[1]+ Running firefox &
[zy@localhost ~]$ ps -le | grep -v "grep" | grep -i "12396"
0 S 1000 12396 11993 2 80 0 - 515651 poll_s pts/2 00:00:01 firefox
0 S 1000 12466 12396 0 80 0 - 437019 poll_s ? 00:00:00 Web Content
[zy@localhost ~]$
[zy@localhost ~]$ ps -le | grep -v "grep" | grep -i "11993"
0 S 1000 11993 11986 0 80 0 - 29043 do_wai pts/2 00:00:00 bash
0 S 1000 12396 11993 2 80 0 - 515651 poll_s pts/2 00:00:01 firefox
0 R 1000 12558 11993 0 80 0 - 37235 - pts/2 00:00:00 ps
[zy@localhost ~]$
[zy@localhost ~]$ nohup firefox &
[1] 13330
nohup: ignoring input and appending output to ‘nohup.out’
[zy@localhost ~]$ jobs
[1]+ Running nohup firefox &
[zy@localhost ~]$ ps -le | grep -v "grep" | grep -i "13330"
0 S 1000 13330 13034 5 80 0 - 518469 poll_s pts/2 00:00:01 firefox
0 S 1000 13400 13330 1 80 0 - 434970 poll_s ? 00:00:00 Web Content
[zy@localhost ~]$
[zy@localhost ~]$ ps -le | grep -v "grep" | grep -i "13034"
0 S 1000 13034 13027 0 80 0 - 29043 do_wai pts/2 00:00:00 bash
0 S 1000 13330 13034 3 80 0 - 518469 poll_s pts/2 00:00:01 firefox
0 R 1000 13473 13034 0 80 0 - 37235 - pts/2 00:00:00 ps
[zy@localhost ~]$
[root@localhost ~]
0 S 1000 13330 1 1 80 0 - 519945 poll_s ? 00:00:02 firefox
[root@localhost ~]
16.9 守护进程 - deamon
$# 1. 特点
(web服务 - httpd) http deamon(sftp服务 - vsftpd) vsftp deamon
$# 2.
1. 命令实现
2. 代码构建
[zy@localhost Desktop]$ touch zy_keeplived
[zy@localhost Desktop]$ ls
zy_keeplived
[zy@localhost Desktop]$ vim zy_keeplived
import time
import oswhile True:os.system("date")time.sleep(1)
~
[zy@localhost Desktop]$
[zy@localhost Desktop]$ /usr/bin/python2 zy_keeplived
Sun Feb 5 00:14:50 CST 2023
Sun Feb 5 00:14:51 CST 2023
Sun Feb 5 00:14:52 CST 2023
Sun Feb 5 00:14:53 CST 2023
Sun Feb 5 00:14:54 CST 2023
[zy@localhost Desktop]$[zy@localhost Desktop]$
[zy@localhost Desktop]$ chmod u+x zy_keeplived
[zy@localhost Desktop]$ vim zy_keeplived
import time
import oswhile True:os.system("date")time.sleep(1)
~
[zy@localhost Desktop]$ ls
zy_keeplived
[zy@localhost Desktop]$ ./zy_keeplived
======================================================================================$# 3. 命令构建 独立于shell
[zy@localhost Desktop]$ vim zy_keeplived
import time
import oswhile True:os.system("date >> /home/zy/heartbeat")time.sleep(1)
~
~
~
[zy@localhost Desktop]$ ./zy_keeplived
[root@localhost ~]heartbeat
[root@localhost ~]
[root@localhost ~]
Sun Feb 5 00:22:41 CST 2023
Sun Feb 5 00:22:42 CST 2023
Sun Feb 5 00:22:43 CST 2023
Sun Feb 5 00:22:44 CST 2023
Sun Feb 5 00:22:45 CST 2023
[root@localhost ~]
[root@localhost ~]
[root@localhost ~][zy@localhost Desktop]$ nohup ./zy_keeplived &
[1] 14930
nohup: ignoring input and appending output to ‘nohup.out’
[zy@localhost Desktop]$
[zy@localhost Desktop]$ jobs
[1]+ Running nohup ./zy_keeplived &
[zy@localhost Desktop]$
[zy@localhost Desktop]$ ./zy_keeplived [root@localhost ~]
zy 14930 13785 0 00:28 pts/2 00:00:00 /usr/bin/python2 ./zy_keeplived
zy 15209 13785 0 00:30 pts/2 00:00:00 /usr/bin/python2 ./zy_keeplived
[root@localhost ~]
[root@localhost ~]
zy 14930 1 0 00:28 ? 00:00:00 /usr/bin/python2 ./zy_keeplived
[root@localhost ~]
======================================================================================$# 4. 进程文件信息
[root@localhost 1]
/proc/1
[root@localhost 1]
Threads: 1
SigQ: 0/7156
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 7be3c0fe28014a03
SigIgn: 0000000000001000
SigCgt: 00000001800004ec
CapInh: 0000000000000000
CapPrm: 0000001fffffffff
CapEff: 0000001fffffffff
CapBnd: 0000001fffffffff
CapAmb: 0000000000000000
NoNewPrivs: 0
Seccomp: 0
Speculation_Store_Bypass: thread vulnerable
Cpus_allowed: ffffffff,ffffffff,ffffffff,ffffffff
Cpus_allowed_list: 0-127
Mems_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001
Mems_allowed_list: 0
voluntary_ctxt_switches: 4487
nonvoluntary_ctxt_switches: 3376
[root@localhost 1]
16.10 进程优先级调整
$# 1. [root@localhost ~]
0 S 1000 2544 2311 0 80 0 - 31347 poll_s pts/0 00:00:00 zy_keeplived
[root@localhost ~]
[zy@localhost Desktop]$ nohup nice -n +10 ./zy_keeplived &
[3] 15818
nohup: ignoring input and appending output to ‘nohup.out’
[zy@localhost Desktop]$ [root@localhost ~]
0 S 1000 2544 2311 0 80 0 - 31347 poll_s pts/0 00:00:00 zy_keeplived
0 S 1000 2595 2311 0 80 0 - 31347 poll_s pts/0 00:00:00 zy_keeplived
0 S 1000 15818 2311 0 90 10 - 31347 poll_s pts/0 00:00:00 zy_keeplived
[root@localhost ~]$# 2. renice 重新调整进程优先级
[zy@localhost Desktop]$ renice -n +5 15818
renice: failed to set priority for 15818 (process ID): Permission denied
[zy@localhost Desktop]$ id zy
uid=1000(zy) gid=1000(zy) groups=1000(zy)
[zy@localhost Desktop]$
[zy@localhost Desktop]$ renice -n +12 15818
15818 (process ID) old priority 10, new priority 12
[zy@localhost Desktop]$ renice -n +11 15818
renice: failed to set priority for 15818 (process ID): Permission denied
[zy@localhost Desktop]$
[zy@localhost Desktop]$ renice -n +19 15818
15818 (process ID) old priority 12, new priority 19
[zy@localhost Desktop]$ renice -n +20 15818
15818 (process ID) old priority 19, new priority 19
[zy@localhost Desktop]$ [zy@localhost Desktop]$ ps -le | grep -v grep | grep -i zy_keeplived
0 S 1000 2544 2311 0 80 0 - 31347 poll_s pts/0 00:00:00 zy_keeplived
0 S 1000 2595 2311 0 80 0 - 31347 poll_s pts/0 00:00:00 zy_keeplived
0 S 1000 15818 2311 0 99 19 - 31347 poll_s pts/0 00:00:00 zy_keeplived
[zy@localhost Desktop]$ [root@localhost ~]
2595 (process ID) old priority 0, new priority 19
[root@localhost ~]
0 S 1000 2544 2311 0 80 0 - 31347 poll_s pts/0 00:00:00 zy_keeplived
0 S 1000 2595 2311 0 99 19 - 31347 poll_s pts/0 00:00:01 zy_keeplived
0 S 1000 15818 2311 0 99 19 - 31347 poll_s pts/0 00:00:00 zy_keeplived
[root@localhost ~]
[root@localhost ~]
2595 (process ID) old priority 19, new priority -20
[root@localhost ~]
0 S 1000 2544 2311 0 80 0 - 31347 poll_s pts/0 00:00:01 zy_keeplived
0 S 1000 2595 2311 0 60 -20 - 31347 poll_s pts/0 00:00:01 zy_keeplived
0 S 1000 15818 2311 0 99 19 - 31347 poll_s pts/0 00:00:00 zy_keeplived
[root@localhost ~]
======================================================================================
总结:
进程优先级数值越小 - 优先级越低
默认优先级PRI值 - 系统自动判断
可以通过nice,renice方式调整普通用户: 只可以将nice数值调大, 1 到 19
root用户: 可以调整数值调大调小, -20 到 19
======================================================================================