通过进程名称而不是PID杀死Java进程(在Linux中) [英] Kill a java process (in linux) by process name instead of PID

查看:643
本文介绍了通过进程名称而不是PID杀死Java进程(在Linux中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在配置/安装Hadoop集群时,我们经常需要终止Java Process/Daemon. 我们看到使用jps命令运行的Java进程/守护进程. 通常,我们使用其PID终止Java进程.例如

While configuring/installing Hadoop cluster we often need to kill a Java Process/Daemon. We see Java Processes/Daemons running with jps command. Usually we kill a Java process with its PID. E.g.

kill -9 112224

键入PID有点困难.有没有办法杀死它的名字呢?在一个命令中?

It is little bit difficult to type the PID. Is there a way to kill the process by its name? In a single command?

推荐答案

以下是通过进程名"而不是其ProcessID杀死Java进程的命令.

Here is the command to kill the Java process by is Process Name instead of its ProcessID.

kill `jps | grep "DataNode" | cut -d " " -f 1`

让我详细解释一下此命令的好处.假设您正在使用Hadoop集群.通常需要检查使用jps命令运行的Java守护程序.可以说,当在工作节点上给出此命令时,将看到以下输出.

Let me explain more, about the benefit of this command. Lets say you are working with Hadoop cluster. Its often required that you check java daemons running with jps command. Lets say when you give this command on worker nodes, you see following output.

1915 NodeManager
18119 DataNode
17680 Jps

通常,如果要终止DataNode进程,我们将使用以下命令

Usually, if we want to kill DataNode process, we would use following command

kill -9 18119

但是,使用kill命令键入PID有点困难.通过使用此答案中给出的命令,可以很容易地编写进程的名称.我们还可以准备shell脚本来杀死hadoop集群中的常用恶魔, 或者我们可以准备一个shell脚本,并可以使用参数作为进程名称.

But, it is little bit difficult to type the PID, to use kill command. By using the command, given in this answer, it is easy to write the name of the process. We can also prepare shell scripts to kill commonly used deamons in hadoop cluster, or we can prepare one shell script and can use parameter as process name.

这篇关于通过进程名称而不是PID杀死Java进程(在Linux中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆