作用
killall - kill processes by name
killall sends a signal to all processes running any of the specified commands. If no signal name is specified, SIGTERM is sent. Signals can be specified either by name (e.g. -HUP or -SIGHUP) or by number (e.g. -1) or by option -s.
If the command name is not regular expression (option -r) and contains a slash (/), processes executing that particular file will be selected for killing, independent of their name.
killall returns a zero return code if at least one process has been killed for each listed command, or no commands were listed and at least one process matched the -u and -Z search criteria. killall returns non-zero otherwise.
A killall process never kills itself (but may kill other killall processes)
用法
命令格式
1 | killall [-Z CONTEXT] [-u USER] [ -eIgiqrvw ] [ -SIGNAL ] NAME... |
命令参数
1 | -e,--exact require exact match for very long names |
1 | -e,--exact 精准匹配。由于命令名长于15个字符时,会杀死匹配前15个字符的所有进程。此时需要使用-e选项进行精准匹配。 |
用法示例
查看版本
1 | [root@hadoop-centos-01 ~]# killall -V |
查看信号列表
1 | [root@hadoop-centos-01 ~]# killall -l |
常用的信号说明:
HUP(1,终端断线),
INT(2,中断,同<Ctrl>+c)
QUIT(3,退出,同<Ctrl>+\)
KILL(9,强制终止)
TERM(15,缺省信号,终止,正常结束)
CONT(18,继续,同fg/bg命令)
STOP(19,停止)
TSTP(20,暂停,同<Ctrl>+Z)
杀死所有同名进程
1 | [root@hadoop-centos-01 ~]# ps -aux | grep python |
向进程发送指定信号
1 | [root@hadoop-centos-01 ~]# ps -aux | grep python |
杀掉所有的登录后的shell
1 | [root@hadoop-centos-01 ~]# killall -9 bash |