自动杀死进程 - linux

时间:2013-03-12 18:13:20

标签: linux grep kill-process

我正在运行此命令:

pgrep -l someprocess

我得到了一些输出XXXX someprocess

然后我杀死手工出现的每个进程,我想编写一个脚本来自动执行,但这没有意义  kill -9 $(pgrep -l someprocess | grep "^[0-9]{4}")

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:5)

您可以使用pkillkillall来完成此任务。

我发现this简短明了的摘要,解释了kill流程的不同方式。

pkill非常简单:pkill someprocess

@ewm在答案中已经包含了关于killall的详细说明,所以我不在此重复。

答案 1 :(得分:3)

你可能想看看'killall'命令:

KILLALL(1)用户命令KILLALL(1)

NAME        killall - 按名称杀死进程

概要        killall [-Z, - context pattern] [-e, - exact] [-g, - process-group] [-i, - interactive] [-q, - quiet]        [-r, - regexp] [-s, - signal signal] [-u, - user user] [-v, - verbose] [-w, - wait] [-I, - ignore-案件]        [-V, - 版本] [ - ]名字......        基拉尔-l        killall -V, - 版本

说明        killall向运行任何指定命令的所有进程发送信号。如果没有信号名称        指定,SIGTERM被发送。

   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 execut-
   ing 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).
相关问题