20181203使用信號控制進程

使用信號控制進程

kill(只能跟PID或JOB ID),killall(name),pgrep,pkill,top
20181203使用信號控制進程
給進程發送信號
[root@tianyun ~]# kill -l //列出全部支持的信號
編號 信號名
1) SIGHUP 從新加載配置 PID 不變
2) SIGINT 鍵盤中斷^C
3) SIGQUIT 鍵盤退出
9) SIGKILL 強制終止
15) SIGTERM 終止(正常結束),缺省信號,容許去釋放資源
18) SIGCONT 繼續
19) SIGSTOP 中止
20)SIGTSTP 暫停^Z
做業 1: 給 vsftpd 進程發送信號 1,15
vsftpd 信號測試
[root@tianyun ~]# yum -y install vsftpd 安裝FTP服務
[root@dong ~]# /etc/init.d/vsftpd restart 爲 vsftpd 啓動 vsftpd
[root@dong ~]# /etc/init.d/vsftpd stop 關閉 vsftpd
[root@tianyun ~]# ps aux |grep vsftpd
root 9160 0.0 0.0 52580 904 ? Ss 21:54 0:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.confbash

[root@tianyun ~]# kill -1 9160 //發送重啓信號,例如 vsftpd 的配置文件發生改變,但願從新加載
root 9160 0.0 0.0 52580 904 ? Ss 21:54 0:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.confide

[root@tianyun ~]# kill 9160 //發送中止信號,vsftpd 服務有中止的腳本 systemctl stop vsftpd(默認就是15)
[root@tianyun ~]# ps aux |grep vsftpd
做業 2:crond 信號測試
//1 hup
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ ps aux |grep crond
root 478 0.0 0.1 124144 1572 ? Ss 09:35 0:00 /usr/sbin/crond -n測試

[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ sudo kill -1 478
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ ps aux |grep crond PID不變
root 478 0.0 0.1 124144 1572 ? Ss 09:35 0:00 /usr/sbin/crond -nrest

//15 term
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ sudo kill 478
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ ps aux |grep crondblog

[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ sudo systemctl start crond
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ ps aux |grep crond 進程重啓後PID改變
root 22319 0.0 0.1 124140 1548 ? Ss 14:54 0:00 /usr/sbin/crond -n進程

做業 3: 信號測試18,19
[root@dong ~]# ps aux |grep vsftpd
root 2737 0.0 0.0 52580 824 ? Ss 10:38 0:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
//19 stop
[root@dong ~]# kill -19 2737
[root@dong ~]# ps aux |grep vsftpd
root 2737 0.0 0.0 52580 824 ? Ts 10:38 0:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
root 2806 0.0 0.0 103256 844 pts/0 S+ 10:59 0:00 grep vsftpd
//18 cont
[root@dong ~]# kill -18 2737
[root@dong ~]# ps aux |grep vsftpd
root 2737 0.0 0.0 52580 824 ? Ss 10:38 0:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
root 2815 0.0 0.0 103256 844 pts/0 S+ 11:00 0:00 grep vsftpd資源

做業 4:踢出一個從遠程登陸到本機的用戶
[root@dong ~]# w
15:56:09 up 2:16, 6 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.1.144 10:10 4:28m 0.72s 0.72s -bash
dong1 pts/1 192.168.1.144 10:10 5:39m 0.08s 0.08s -bash
root pts/2 192.168.1.144 12:12 3:21m 0.11s 0.11s -bash
dong1 pts/3 192.168.1.144 12:19 3:28m 0.08s 0.08s -bash
root pts/4 192.168.1.144 15:50 0.00s 0.15s 0.01s w
hr01 pts/5 192.168.1.144 15:50 5:44 0.04s 0.04s -bashit

[root@dong ~]# pkill -u hr01 結束用戶hr01的進程class

[root@dong ~]# w
15:56:19 up 2:16, 5 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.1.144 10:10 4:28m 0.72s 0.72s -bash
dong1 pts/1 192.168.1.144 10:10 5:39m 0.08s 0.08s -bash
root pts/2 192.168.1.144 12:12 3:21m 0.11s 0.11s -bash
dong1 pts/3 192.168.1.144 12:19 3:28m 0.08s 0.08s -bash
root pts/4 192.168.1.144 15:50 0.00s 0.16s 0.00s w登錄


[root@dong ~]# w
15:58:16 up 2:18, 6 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.1.144 10:10 4:30m 0.72s 0.72s -bash
dong1 pts/1 192.168.1.144 10:10 5:41m 0.08s 0.08s -bash
root pts/2 192.168.1.144 12:12 3:23m 0.11s 0.11s -bash
dong1 pts/3 192.168.1.144 12:19 3:30m 0.08s 0.08s -bash
root pts/4 192.168.1.144 15:50 0.00s 0.37s 0.21s w
dong1 pts/5 192.168.1.144 15:58 3.00s 0.05s 0.00s sleep 10000

[root@dong ~]# pkill -t pts/5 //終止 pts/5上全部進程
[root@dong ~]# w
15:59:04 up 2:19, 6 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.1.144 10:10 4:31m 0.72s 0.72s -bash
dong1 pts/1 192.168.1.144 10:10 5:42m 0.08s 0.08s -bash
root pts/2 192.168.1.144 12:12 3:24m 0.11s 0.11s -bash
dong1 pts/3 192.168.1.144 12:19 3:31m 0.08s 0.08s -bash
root pts/4 192.168.1.144 15:50 0.00s 0.17s 0.00s w
dong1 pts/5 192.168.1.144 15:58 51.00s 0.05s 0.05s -bash


[root@dong ~]# pkill -9 -t pts/5 //終止 pts/5 上全部進程 並結束該 pts/5[root@dong ~]# w16:00:09 up 2:20, 5 users, load average: 0.00, 0.00, 0.00USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATroot pts/0 192.168.1.144 10:10 4:32m 0.72s 0.72s -bashdong1 pts/1 192.168.1.144 10:10 5:43m 0.08s 0.08s -bashroot pts/2 192.168.1.144 12:12 3:25m 0.11s 0.11s -bashdong1 pts/3 192.168.1.144 12:19 3:32m 0.08s 0.08s -bashroot pts/4 192.168.1.144 15:50 0.00s 0.20s 0.03s w

相關文章
相關標籤/搜索