RHCSA教程 第八章 进程监控及管理
yum install -y psmisc
pstree -p
一程序被开启会产生一个或多个进程,他们都有对应父进程与子进程,每个进程都有进程号PID systemd 1 不能被杀死,除非重启,关机。
1.ps
以静态的方式查看系统进程
ps -l
ps aux
ps aux | grep http
[root@servera ~]# ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 27392 27367 0 80 0 - 85532 - pts/0 00:00:00 su
4 S 0 27396 27392 0 80 0 - 59008 - pts/0 00:00:00 bash
4 T 0 27822 27396 1 80 0 - 63962 - pts/0 00:00:00 vim
0 R 0 27823 27396 0 80 0 - 63625 - pts/0 00:00:00 ps
练习:
查看httpd进程 1、【node1】: yum install -y httpd 2、systemctl start httpd 3、ps aux |grep httpd 4、【foundation】 firefox 172.25.250.10
模拟考试环境yum源配置
[root@node1 /]# cat /etc/yum.repos.d/rhel.repo
[rhel]
name=rhel
baseurl=http://foundation0.ilt.example.com/dvd/BaseOS
gpgcheck=0
[rhel1]
name=rhel1
baseurl=http://foundation0.ilt.example.com/dvd/AppStream
gpgcheck=0
2.top
以同态的形式查看进程 top M P h k pid 9/15 q 退出
终止进程
kill
语法:
kill -s 信号名称 或-n 信号编号
Options:
-s sig SIG is a signal name
-n sig SIG is a signal number
例子:
kill -s SIGKILL httpd
kill -n 9 httpd # 或 kill -9 httpd
练习:
[root@node1 /]# kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
[root@node1 /]# vim 1 &
[1] 1372
[root@node1 /]# ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 0 1313 1312 0 80 0 - 59084 - pts/1 00:00:00 bash
0 T 0 1372 1313 4 80 0 - 60816 - pts/1 00:00:00 vim
0 R 0 1373 1313 0 80 0 - 63799 - pts/1 00:00:00 ps
[1]+ Stopped vim 1
[root@node1 /]# kill -n 9 1372
[root@node1 /]# ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 0 1313 1312 0 80 0 - 59084 - pts/1 00:00:00 bash
0 R 0 1374 1313 0 80 0 - 63799 - pts/1 00:00:00 ps
[1]+ Killed vim 1
killall
语法:
killall 守护进程名称
#yum install -y httpd
systemctl start httpd
ps aux | grep httpd
killall httpd
yum provides killall
yum install -y psmisc-23.1-3.el8.x86_64
killall httpd
ps aux | grep httpd
pkill
3.作业控制jobs
[root@servera ~]# vim file2 (ctrl+z)
[1]- Stopped vim file1
[2]+ Stopped vim file2
[root@servera ~]# jobs
[1]- Stopped vim file1
[2]+ Stopped vim file2
[root@servera ~]# dd if=/dev/zero of=./bigfile bs=1M count=1000
ctrl + z
[root@servera ~]# jobs
[1]+ Stopped dd if=/dev/zero of=./bigfile bs=1M count=1000
[root@servera ~]# bg %1
[1]+ dd if=/dev/zero of=./bigfile bs=1M count=1000 &
[root@servera ~]# jobs
[1]+ Running dd if=/dev/zero of=./bigfile bs=1M count=1000 &
[root@servera ~]# fg %1
[root@servera ~]#
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB, 1000 MiB) copied, 65.0049 s, 16.1 MB/s
[root@servera ~]# kill -9 %2
[2]- Stopped vim file2
[root@servera ~]# jobs
[2]- Killed vim file2
[3]+ Stopped nice -n -10 vim file4
nice值 超级用户root 可以修改nice值范围 -20~19 普通用户user 可以修改nice值范围 0-19 进程优先级数字越小,优先级越高。 优先级不能直接改,可以通过nice值来影响优先级。 旧优先级 + nice值 = 新优先级 80 -10 = 70 两种方法: 一、产生新进程时,设置nice值 nice -n -5 vim file2 & 二、修改现有进程nice值 renice -n 10 PID ps -l 查看需要更改的进程号 renice -n 10 28183
THE END