使用信号控制进程

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

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

[root@localhost ~]# kill 9160 //发送停止信号
[root@localhost ~]# 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@localhost ~]# touch file1 file2
[root@localhost ~]# tty
/dev/pts/1
[root@localhost ~]# vim file1

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

[root@localhost ~]# 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@localhost ~]# kill 4362
[root@localhost ~]# kill -9 4363

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

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

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

[root@localhost ~]# kill -cont 5571
[root@localhost ~]# 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@localhost ~]# 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@localhost ~]# pkill -u alice

[root@localhost ~]# 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

linux进程管理之信号控制的更多相关文章

  1. 12个Linux进程管理命令介绍(转)

    12个Linux进程管理命令介绍 [日期:2015-06-02] 来源:Linux中国  作者:Linux [字体:大 中 小]   执行中的程序在称作进程.当程序以可执行文件存放在存储中,并且运行的 ...

  2. Linux进程管理知识整理

    Linux进程管理知识整理 1.进程有哪些状态?什么是进程的可中断等待状态?进程退出后为什么要等待调度器删除其task_struct结构?进程的退出状态有哪些? TASK_RUNNING(可运行状态) ...

  3. [转帖]十二 个经典 Linux 进程管理命令介绍

    https://www.cnblogs.com/swordxia/p/4550825.html 接了 http referer 头 没法显示图片 可以去原始blog 里面去查看.   随笔- 109  ...

  4. Linux 进程管理 笔记

    https://www.ibm.com/developerworks/cn/linux/l-linux-process-management/index.htmlLinux 进程管理剖析 进程可以是短 ...

  5. 《Linux性能及调优指南》----1.1 Linux进程管理

    翻译:飞哥 ( http://hi.baidu.com/imlidapeng ) 版权所有,尊重他人劳动成果,转载时请注明作者和原始出处及本声明. 原文名称:<Linux Performance ...

  6. 《Linux性能及调优指南》 Linux进程管理

    版权所有: 原文名称:<Linux Performance and Tuning Guidelines> 原文地址:http://www.redbooks.ibm.com/abstract ...

  7. [转帖]linux进程管理总结

    linux进程管理总结 https://www.cnblogs.com/chenfangzhi/p/10660355.html 高手总结的.. 看出来我是菜逼. 目录 一.进程相关的概念 二.关闭会话 ...

  8. linux 进程管理和内存分配

    1.进程相关概念 进程:正在运行中的程序 内核功用:进程管理.文件系统.网络功能.内存管理.驱动程序.安全功能等 Process:运行中的程序的一个副本,是被载入内存的一个指令集合 进程 ID(Pro ...

  9. Linux进程管理工具Supervisor的安装配置

    目录 Linux进程管理工具Supervisor的安装配置 简介 安装Python包管理工具 安装Supervisor 配置 配置文件参数说明 配置进程管理 启动supervisor 控制进程 交互终 ...

随机推荐

  1. Bootstrap3基础 btn-primary/warning... 三类按钮的六种样式

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  2. cf213E 线段树维护hash

    链接 https://codeforces.com/contest/213/problem/E 题目大意 给出两个排列a.b,长度分别为n.m,你需要计算有多少个x,使 得\(a_1 + x; a_2 ...

  3. (转)JPA & Restful

    参考博客: JPA: https://www.jianshu.com/p/b6932740f3c0 https://shimo.im/docs/zOer2qMVEggbF33d/ Restful: h ...

  4. Depth-first search and Breadth-first search 深度优先搜索和广度优先搜索

    Depth-first search Depth-first search (DFS) is an algorithm for traversing or searching tree or grap ...

  5. hihoCoder week10 后序遍历

    题目链接 https://hihocoder.com/contest/hiho10/problem/1 给出先序  中序 求 后序 #include <bits/stdc++.h> usi ...

  6. Optical Flow related Tutorials

    Optical Flow related Tutorials 2017-04-01 10:50:55 Reference: 1. http://blog.csdn.net/carson2005/art ...

  7. Nuget 打包 for .Net Standart project

    Create .NET Standard packages with Visual Studio 2015 Publishing packages nuge.exe 放在项目目录中 nuget spe ...

  8. std::cout << char + int

    #include<iostream> int main(){ char ch; std::cout << "Type, and I shall repeat.\n&q ...

  9. Wijmo 2017路线图

    2016年是Wijmo团队发展和增长的另一个富有成效的一年.回顾我们2016年的路线图,您可以看到我们交付了我们承诺的一切.让我们回顾一下2016年的亮点: 我们第一个全面支持Angular 2 互操 ...

  10. VHDL 例程

    以下程序未经仿真,仅供说明 语法 声明参考库ieee,使用ieee中的std_logic_1164包全部条目可见 library ieee; use ieee.std_logic_1164.all; ...