linux killall_使用killall命令杀死Linux进程

linux killall

linux killall

We have previously looked the command kill to kill process accordion to their names, owners, etc. But using only kill command to kill a process according to its owner is done with supportive commands like grep. In this tutorial, we will look more compact and all in one command killall .

以前我们已经根据命令的名称,所有者等查看了kill kill命令来杀死进程,但是仅使用kill命令根据其所有者杀死进程是通过支持命令(例如grep)来完成的。 在本教程中,我们将看起来更紧凑,并且所有命令都可以使用killall

killall命令语法 (killall Command Syntax)

The syntax of the killall command is like below.

killall命令的语法如下。

Usage: killall [-Z CONTEXT] [-u USER] [ -eIgiqrvw ] [ -SIGNAL ] NAME... 
       killall -l, --list 
       killall -V, --version
Syntax
Syntax
句法

killall命令帮助(killall Command Help)

Simple and fast help information about the command can be listed below. As we see below killall command provides features like exact process name match, ignoring case, interactive usage, verbose or debug mode operation.

有关该命令的简单和快速帮助信息可以在下面列出。 正如我们在下面看到的, killall命令提供了一些功能,例如精确的进程名称匹配,忽略大小写,交互式用法,详细或调试模式操作。

$ killall -h
Help
帮帮我

用ps列出进程(List Process With ps)

Killall provides convenient ways to kill a process with its name listing process and using complete process names will make killall operations more reliable. We will list all processes in the system where the user-related process will generally list in the below of the output.

Killall提供了使用其名称列表进程杀死进程的便捷方法,使用完整的进程名称将使killall操作更加可靠。 我们将列出系统中所有与用户相关的进程,这些进程通常会在输出的下面列出。

$ ps uax
List Process With ps
List Process With ps
用ps列出进程

杀死过程(Kill Process)

Now we can start kill processes according to their name. This example is a simple example where we only provide some term which resides in the process name. Our process is watch ls like below.

现在我们可以根据它们的名称开始杀死进程。 这个例子是一个简单的例子,其中我们只提供了一些驻留在进程名称中的术语。 我们的过程是watch ls下方喜欢。

$ ps uax | grep "watch ls"

Now we can provide the term watch to the killall command like below. And after that command, we can process and see that is killed.

现在,我们可以将术语“ watch提供给killall命令,如下所示。 在执行该命令之后,我们可以进行处理并看到它被杀死了。

$ killall watch

使用确切的进程名称杀死 (Kill With Exact Process Name)

In the previous example, we have only provided some part of the process name, not the whole. In some situations, this can not be suitable because of similarly named processes. We can specify the exact name to exactly specify the process. In this example, we have two processes with similar names as we can see below.

在前面的示例中,我们仅提供了流程名称的一部分,而不是全部。 在某些情况下,由于名称相似的过程,因此可能不合适。 我们可以指定确切的名称来精确地指定过程。 在此示例中,我们有两个名称相似的进程,如下所示。

$ ps uax | grep "watch ls"
Kill With Exact Process Name
Kill With Exact Process Name
使用确切的进程名称杀死

Now we only want to kill process watch ls which PID is 3733 . But we do not want to kill watchgnupg which PID is 3732 . Now we will provide process name with the -e parameter to match the exact name of the process like below.

现在我们只想杀死PID为3733的过程watch ls 。 但是我们不想杀死PID为3732的watchgnupg 。 现在,我们将提供带有-e参数的进程名称,以匹配该进程的确切名称,如下所示。

$ killall -e "watch"
Kill With Exact Process Name
Kill With Exact Process Name
使用确切的进程名称杀死

We check again the running processes and see only watchgnupg process.

我们再次检查正在运行的进程,仅查看watchgnupg进程。

LEARN MORE  How To Pause and Resume Powershell and Cmd Scripts In Windows With Examples?
了解更多信息如何通过示例在Windows中暂停和恢复Powershell和Cmd脚本?

忽略进程名称的区分大小写 (Ignore Casesensitivity For Process Name)

While killing processes the name of the processes is important. The process name can be upper case or lowercase which is not deterministic. In these situations using ignore case parameters is important. -I parameter can be provided to ignore casesensitivity like below. In the example below, we can see that there is an instance of watch . We will kill by providing uppercase WATCH term like below.

在终止进程时,进程的名称很重要。 进程名称可以是大写或小写的,不确定。 在这些情况下,使用忽略大小写参数很重要。 可以提供-I参数来忽略大小写,如下所示。 在下面的示例中,我们可以看到有一个watch实例。 我们将通过提供如下所示的大写WATCH术语来杀死用户。

$ killall -I WATCH
Ignore Case
Ignore Case
忽略大小写

根据进程所有者或用户名杀死(Kill According To Process Owner or User Name)

As we know every Linux process has an owner user name. Killall command supports killing processes according to their user names. Keep in mind that this will kill all processes of the specified user. In these examples we want to kill user name ismail processes.

众所周知,每个Linux进程都有一个所有者用户名。 Killall命令支持根据用户名杀死进程。 请记住,这将终止指定用户的所有进程。 在这些示例中,我们要ismail用户名ismail进程。

$ killall -u ismail
Kill According To Process User Name
Kill According To Process User Name
根据进程用户名杀死

As we see we have killed also our ssh session which the user name was ismail too.

如我们所见,我们也杀死了ssh会话,该会话的用户名也为ismail。

根据进程组名称杀死 (Kill According To Process Group Name)

As we know every Linux process has an owner group name. And this feature is the same as killing according to the user name. We only provide the group name of the processes with the -g option like below.

众所周知,每个Linux进程都有一个所有者组名称。 并且此功能与根据用户名进行杀死相同。 我们仅使用-g选项提供进程的组名,如下所示。

$ killall -g ismail

在终止进程之前进行确认 (Confirm Before Killing Processes)

Up to now, we have killed processes harshly without warning of a confirmation. There is an option to ask about confirmation while killing processes like below. The option is -i . This option is defined also interactively because of its usage way. While killing processes also the PID is provided for stability.

到目前为止,我们已经严厉取消了进程,没有发出确认的警告。 在杀死如下所示的进程时,可以选择询问确认信息。 选项是-i 。 由于其使用方式,因此也以交互方式定义此选项。 在终止进程的同时,还提供了PID以保持稳定性。

$ killall -i watch

根据运行时间终止进程 (Kill Processes According to Running Time)

There is another interesting feature of the killall command. Processes can be killed according to their run time. In this example, we will kill all processes that run more than 1 minute. This option is -o

killall命令还有另一个有趣的功能。 可以根据进程的运行时间终止进程。 在此示例中,我们将终止所有运行超过1分钟的进程。 此选项是-o

$ killall -o 1m watch

Also, we can kill processes less than specified time. This is feature is expressed as -y option.

此外,我们可以在少于指定时间的时间内终止进程。 此功能表示为-y选项。

$ killall -y 5h watch

We can below how the time is expressed for this feature.

我们可以在下面显示该功能的时间表示方式。

  • s  seconds

    s

  • m minutes

    m分钟

  • h hours

    h小时

  • d days

    d

  • w weeks

    w

  • M months

    M个月

  • y years

    y

LEARN MORE  Python Subprocess and Popen() with Examples
了解更多Python子进程和Popen()及其示例

对过程名称使用正则表达式(Using Regular Expression For Process Names)

Up to now, we have used specific processes names. This is simple to express but there are times where we need to expresses generic processes names that are similar but not the same. Regular expressions are the way to express structural parts in the text. In this example, we will kill all processes that start with w and ends with h.

到目前为止,我们已经使用了特定的进程名称。 这很容易表达,但是有时我们需要表达相似但不相同的通用过程名称。 正则表达式是在文本中表达结构部分的方式。 在此示例中,我们将终止所有以w开头和以h结尾的进程。

$ killall -r "w.*h$"
Using Regular Expression For Process Names
Using Regular Expression For Process Names
对过程名称使用正则表达式

In this example only the watch processes are killed because we have restricted regular expression that the end of the processes name must be h . So only watch processes are matched and killed.

在此示例中,仅watch进程被杀死,因为我们限制了正则表达式,即进程名称的末尾必须为h 因此,只有监视进程被匹配并杀死。

翻译自: https://www.poftut.com/killing-linux-processes-killall-command/

linux killall

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值