pkill

使用完整或进程名杀死进程
pkill是ps命令和kill命令的结合,按照进程名来杀死指定进程

语法

  pkill [-signal] [-fvx] [-n|-o] [-P ppid,...] [-g pgrp,...]
     [-s sid,...] [-u euid,...] [-U uid,...] [-G gid,...]
        [-t term,...] [pattern]

选项



   pattern
      用于匹配进程名称或命令行的扩展正则表达式
   -f
       该模式通常仅与进程名称匹配。
       设置-f时,使用完整的命令行
   -g pgrp,...
       仅匹配列出的进程组ID中的进程
   -G gid,...
       仅匹配列出实际组ID的进程。
       可以使用数值或符号值。 
   -n
       仅选择最新(最近启动)的匹配流程
   -o
       仅选择最早(最近最少启动)的匹配流程
   -P ppid,...
       仅匹配列出其父进程ID的进程。
   -s sid,...
       仅匹配列出进程会话ID的进程。
   -t term,...
       仅匹配列出控制终端的进程。
   -u euid,...
       仅匹配列出有效用户ID的进程。
   -U uid,...
       仅匹配列出了真实用户ID的进程. 
   -v
      否定匹配。
   -x
       仅匹配其名称(或命令行,如果指定了-f)的进程
       完全匹配模式
   -signal
       定义要发送到每个匹配进程的信号。
       可以使用数字或符号信号名称。

pkill在正在运行的系统上搜索进程表,并发出符合命令行上给出的条件的所有进程的信号

实例

1: 查找named守护程序的进程ID

$ pgrep -u root named

使syslog重新读取其配置文件:

$ pkill -HUP syslogd

提供有关所有xterm进程的详细信息:

$ ps -fp $(pgrep -d, -x xterm)

使所有netscape进程运行renice :

$ renice +4 ‘pgrep netscape’

常见的 Kill 信号

信号名称  信号值	   影响
SIGHUP	    1	   挂断
SIGINT	    2	   键盘中断
SIGQUIT     3	   放弃
SIGABRT	    6	   退出
SIGKILL	    9	   杀死信号
SIGTERM	    15	   终止信号 - 允许有序关机
SIGSTOP	   17,19,23	停止这个进程

退出状态

  1. 一个或多个进程符合标准
  2. 没有匹配的进程
  3. 命令行中的语法错误
  4. 致命错误:内存不足等

pkill 命令实例:

linux命令:pkill -HUP syslogd syslogd -HUP pkill pkill -HUP syslogdrootopen.com
linux命令:pkill -HUP syslogd syslogd -HUP pkill pkill -HUP syslogdrootopen.com
2018-05-01 14:54:48

linux命令:pkill -f foo foo -f pkill pkill -f foorootopen.com
linux命令:pkill -f foo foo -f pkill pkill -f foorootopen.com
2018-02-09 23:44:48

linux命令:pkill -U MYWIFE MYWIFE -U pkill pkill -U MYWIFErootopen.com
linux命令:pkill -U MYWIFE MYWIFE -U pkill pkill -U MYWIFErootopen.com
2018-05-27 07:47:48

linux命令:pkill -n firefox firefox -n pkill pkill -n firefoxrootopen.com
linux命令:pkill -n firefox firefox -n pkill pkill -n firefoxrootopen.com
2018-01-12 17:09:48

linux命令:pkill pkill pkillrootopen.com
linux命令:pkill pkill pkillrootopen.com
2018-02-12 00:59:48

linux命令:pkill $1 $1 pkill pkill $1rootopen.com
linux命令:pkill $1 $1 pkill pkill $1rootopen.com
2018-04-08 22:32:48

linux命令:pkill -x firefox firefox -x pkill pkill -x firefoxrootopen.com
linux命令:pkill -x firefox firefox -x pkill pkill -x firefoxrootopen.com
2018-04-27 10:47:48

linux命令:pkill -USR1 ^dd$ ^dd$ -USR1 pkill pkill -USR1 ^dd$rootopen.com
linux命令:pkill -USR1 ^dd$ ^dd$ -USR1 pkill pkill -USR1 ^dd$rootopen.com
2018-03-23 20:21:48

linux命令:pkill <process name> name> <process pkill pkill <process name>rootopen.com
linux命令:pkill <process name> name> <process pkill pkill <process name>rootopen.com
2018-05-15 13:10:48

linux命令:pkill -f <process name> name> <process -f pkill pkill -f <process name>rootopen.com
linux命令:pkill -f <process name> name> <process -f pkill pkill -f <process name>rootopen.com
2018-02-06 16:12:48

linux命令:pkill -9 search_criteria search_criteria -9 pkill pkill -9 search_criteriarootopen.com
linux命令:pkill -9 search_criteria search_criteria -9 pkill pkill -9 search_criteriarootopen.com
2018-04-14 13:33:48

linux命令:pkill <name> <name> pkill pkill <name>rootopen.com
linux命令:pkill <name> <name> pkill pkill <name>rootopen.com
2018-06-08 23:44:48

linux命令:pkill xmms xmms pkill pkill xmmsrootopen.com
linux命令:pkill xmms xmms pkill pkill xmmsrootopen.com
2018-01-12 05:04:48

linux命令:pkill -u `whoami` `whoami` -u pkill pkill -u `whoami`rootopen.com
linux命令:pkill -u `whoami` `whoami` -u pkill pkill -u `whoami`rootopen.com
2018-01-15 05:49:48

linux命令:pkill -0 prog1; while [ $? -eq 0 ]; do sleep 10; pkill -0 prog1; done; prog2 prog2 done; prog1; -0 pkill 10; sleep do ]; 0 -eq $? [ while prog1; -0 pkill pkill -0 prog1; while [ $? -eq 0 ]; do sleep 10; pkill -0 prog1; done; prog2rootopen.com
linux命令:pkill -0 prog1; while [ $? -eq 0 ]; do sleep 10; pkill -0 prog1; done; prog2 prog2 done; prog1; -0 pkill 10; sleep do ]; 0 -eq $? [ while prog1; -0 pkill pkill -0 prog1; while [ $? -eq 0 ]; do sleep 10; pkill -0 prog1; done; prog2rootopen.com
2017-12-25 09:10:48

linux命令:pkill name name pkill pkill namerootopen.com
linux命令:pkill name name pkill pkill namerootopen.com
2018-03-25 01:06:48

linux命令:pkill -KILL -u username username -u -KILL pkill pkill -KILL -u usernamerootopen.com
linux命令:pkill -KILL -u username username -u -KILL pkill pkill -KILL -u usernamerootopen.com
2018-04-18 10:57:48

linux命令:pkill -9 -u username php5-fcgi php5-fcgi username -u -9 pkill pkill -9 -u username php5-fcgirootopen.com
linux命令:pkill -9 -u username php5-fcgi php5-fcgi username -u -9 pkill pkill -9 -u username php5-fcgirootopen.com
2018-02-10 17:43:48

linux命令:pkill -9 -u username php5-fcgi php5-fcgi username -u -9 pkill pkill -9 -u username php5-fcgirootopen.com
linux命令:pkill -9 -u username php5-fcgi php5-fcgi username -u -9 pkill pkill -9 -u username php5-fcgirootopen.com
2018-01-01 00:39:48

linux命令:pkill -{signal} mpg321 mpg321 -{signal} pkill pkill -{signal} mpg321rootopen.com
linux命令:pkill -{signal} mpg321 mpg321 -{signal} pkill pkill -{signal} mpg321rootopen.com
2018-06-09 14:23:48

linux命令:pkill -9 -u username username -u -9 pkill pkill -9 -u usernamerootopen.com
linux命令:pkill -9 -u username username -u -9 pkill pkill -9 -u usernamerootopen.com
2018-01-24 12:58:48

linux命令:pkill -9 -x chrome chrome -x -9 pkill pkill -9 -x chromerootopen.com
linux命令:pkill -9 -x chrome chrome -x -9 pkill pkill -9 -x chromerootopen.com
2018-02-21 10:15:48

linux命令:pkill -f process_name process_name -f pkill pkill -f process_namerootopen.com
linux命令:pkill -f process_name process_name -f pkill pkill -f process_namerootopen.com
2018-01-03 09:09:48

linux命令:pkill plasma-desktop && plasma-desktop plasma-desktop && plasma-desktop pkill pkill plasma-desktop && plasma-desktoprootopen.com
linux命令:pkill plasma-desktop && plasma-desktop plasma-desktop && plasma-desktop pkill pkill plasma-desktop && plasma-desktoprootopen.com
2018-02-15 12:03:48

linux命令:pkill imwheel && imwheel & & imwheel && imwheel pkill pkill imwheel && imwheel &rootopen.com
linux命令:pkill imwheel && imwheel & & imwheel && imwheel pkill pkill imwheel && imwheel &rootopen.com
2018-03-30 20:42:48

Linux的Bash命令行(A-Z排序)