温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

云计算学习路线课程大纲资料:使用信号控制进程

发布时间:2020-08-13 00:39:12 来源:ITPUB博客 阅读:92 作者:千锋云计算 栏目:云计算

今天给大家分享一些云计算学习路线课程大纲资料,这篇文章是关于使用信号控制进程的一些学习笔记资料,希望能给大家一些帮助:

====================================================================================

kill,killall,pgrep,pkill,top


云计算学习路线课程大纲资料:使用信号控制进程


给进程发送信号

[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

[root@tianyun ~]# systemctl start 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.conf

[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.conf

[root@tianyun ~]# kill 9160 //发送停止信号,vsftpd服务有停止的脚本 systemctl stop vsftpd

[root@tianyun ~]# ps aux |grep vsftpd

crond信号测试

//1

[yang@iZm5eiwihahzq6ds23gbf6Z ~]$ ps aux |grep [c]rond

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 [c]rond

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


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI