Kill a java process (on linux) by process name instead of PID

When setting up / installing a Hadoop cluster, we often need to kill the Java Process / Daemon. We see that Java / Daemons processes work with the jps team. Usually we kill the Java process using the PID. For example.

 kill -9 112224 

It's a little difficult to enter PID. Is there a way to kill a process by its name? In one team?

+8
linux process pid
source share
3 answers

Here is the command to kill a Java process - this is the name of the process instead of its ProcessID.

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

Let me explain more about the benefits of this team. Suppose you are working with a Hadoop cluster. It is often required that you check java daemons working with the jps command. Say, when you give this command on work nodes, you see the following result.

 1915 NodeManager 18119 DataNode 17680 Jps 

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

 kill -9 18119 

But, it’s a little difficult to enter a PID to use the kill command. Using the command provided in this answer, it is easy to write the process name. We can also prepare shell scripts to destroy commonly used daemons in a cluster of haops, or we can prepare one shell script and use the parameter as the name of the process.

+20
source share

How about using

 killall firefox 
0
source share

To get the process id for this java process

netstat -tuplen

The process identifier (PID) of this process that you want to kill and run

kill -9 PID

-one
source share

All Articles