使用信号控制进程

 

使用信号控制进程


====================================================================================
kill,killall,pkill,top



给进程发送信号
[root@tianyun ~]# kill -l //列出所有支持的信号
编号 信号名
1) SIGHUP 重新加载配置
2) SIGINT 键盘中断^C
3) SIGQUIT 键盘退出
9) SIGKILL 强制终止
15) SIGTERM 终止(正常结束),缺省信号
18) SIGCONT 继续
19) SIGSTOP 停止
20)SIGTSTP 暂停^Z

作业1: 给vsftpd进程发送信号1,15
[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.conf
[root@tianyun ~]# kill -1 9160 //发送重启信号
root 9160 0.0 0.0 52580 904 ? Ss 21:54 0:00 /usr/sbin/vsftpd/etc/vsftpd/vsftpd.conf

[root@tianyun ~]# kill 9160 //发送停止信号
[root@tianyun ~]# ps aux |grep vsftpd

//1
[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
root 478 0.0 0.1 124144 1572 ? Ss 09:35 0:00 /usr/sbin/crond -n

//15
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ sudo kill 478
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ ps aux |grep crond
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ sudo systemctl start crond
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ ps aux |grep crond
root 22319 0.0 0.1 124140 1548 ? Ss 14:54 0:00 /usr/sbin/crond -n

作业2:信号测试9,15
[root@tianyun ~]# touch file1 file2
[root@tianyun ~]# tty
/dev/pts/1
[root@tianyun ~]# vim file1

[root@tianyun ~]# tty
/dev/pts/2
[root@tianyun ~]# vim file2

[root@tianyun ~]# ps aux |grep vim
root 4362 0.0 0.2 11104 2888 pts/1 S+ 23:02 0:00 vim file1
root 4363 0.1 0.2 11068 2948 pts/2 S+ 23:02 0:00 vim file2

[root@tianyun ~]# kill 4362
[root@tianyun ~]# kill -9 4363

[root@tianyun ~]# killall vim //给所有vim进程发送信号
[root@tianyun ~]# killall httpd

作业3:信号测试18,19
[root@tianyun ~]# ps aux |grep sshd
root 5571 0.0 0.0 64064 1164 ? Ss 09:35 0:00 /usr/sbin/sshd

[root@tianyun ~]# kill -STOP 5571
[root@tianyun ~]# ps aux |grep sshd
root 5571 0.0 0.0 64064 1164 ? Ts 09:35 0:00/usr/sbin/sshd

[root@tianyun ~]# kill -cont 5571
[root@tianyun ~]# ps aux |grep sshd
root 5571 0.0 0.0 64064 1164 ? Ss 09:35 0:00/usr/sbin/sshd

[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ ps aux |grep crond
root 22319 0.0 0.1 124140 1568 ? Ss 14:54 0:00 /usr/sbin/crond -n
yang 22427 0.0 0.0 112648 964 pts/2 R+ 15:07 0:00 grep --color=auto crond
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ sudo kill -19 22319
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ ps aux |grep crond
root 22319 0.0 0.1 124140 1568 ? Ts 14:54 0:00 /usr/sbin/crond -n
yang 22431 0.0 0.0 112648 964 pts/2 R+ 15:07 0:00 grep --color=auto crond
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ sudo kill -cont 22319
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ ps aux |grep crond
root 22319 0.0 0.1 124140 1568 ? Ss 14:54 0:00 /usr/sbin/crond -n
yang 22436 0.0 0.0 112648 960 pts/2 R+ 15:08 0:00 grep --color=auto crond


作业4:踢出一个从远程登录到本机的用户
[root@tianyun ~]# pkill --help
pkill: invalid option -- '-'
Usage: pkill [-SIGNAL] [-fvx] [-n|-o] [-P PPIDLIST] [-g PGRPLIST] [-s SIDLIST]
[-u EUIDLIST] [-U UIDLIST] [-G GIDLIST] [-t TERMLIST] [PATTERN]
[root@tianyun ~]# pkill -u alice

[root@tianyun ~]# w
15:46:44 up 2:19, 4 users, load average: 0.17, 0.12, 0.08
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 :0 21:32 ? 4:22 4:22 /usr/bin/Xorg :
root pts/0 :0.0 15:46 0.00s 0.00s 0.00s w
root pts/3 172.16.8.100 15:46 2.00s 0.01s 0.00s sleep 50000

[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ w
15:17:25 up 5:42, 3 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
yang pts/0 123.120.22.32 15:00 21.00s 0.00s 0.00s -bash
yang pts/1 123.120.22.32 15:00 5.00s 0.00s 0.00s w
yang pts/2 123.120.22.32 12:04 13.00s 0.12s 0.02s vim file1
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ pkill -t pts/2 //终止pts/2上所有进程
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ pkill -9 -t pts/2 //终止pts/2上所有进程 并结束该pts/2

[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ w
15:20:59 up 5:45, 3 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
yang pts/0 123.120.22.32 15:00 3:55 0.00s 0.00s -bash
yang pts/1 123.120.22.32 15:00 3.00s 0.01s 0.00s w
yang pts/2 123.120.22.32 15:20 3.00s 0.00s 0.00s -bash
[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ sudo pkill -u yang




 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值