I want linux script to kill java program running on console.
我想要linux脚本杀死在控制台运行的java程序。
Following is the process running as jar.
下面是作为jar运行的进程。
[rapp@s1-dlap0 ~]$ ps -ef |grep java
rapp 9473 1 0 15:03 pts/1 00:00:15 java -jar wskInterface-0.0.1-SNAPSHOT-jar-with-dependencies.jar
rapp 10177 8995 0 16:00 pts/1 00:00:00 grep java
[rapp@s1-dlap0 ~]$
4 个解决方案
#1
70
You can simply use pkill -f
like this:
你可以像这样简单地使用pkill -f:
pkill -f 'java -jar'
EDIT: To kill a particular java process running your specific jar use this regex based pkill command:
编辑:要杀死运行特定jar的特定java进程,请使用这个基于regex的pkill命令:
pkill -f 'java.*lnwskInterface'
#2
27
If you just want to kill any/all java processes, then all you need is;
如果您只想杀死任何/所有的java进程,那么您所需要的就是;
killall java
If, however, you want to kill the wskInterface process in particular, then you're most of the way there, you just need to strip out the process id;
但是,如果您想要特别地杀死wskInterface过程,那么您是大多数情况下的,您只需要去掉进程id;
PID=`ps -ef | grep wskInterface | awk '{ print $2 }'`
kill -9 $PID
Should do it, there is probably an easier way though...
应该这么做,也许有更简单的方法……
#3
0
Use jps to list running java processes. The command returns the process id along with the main class. You can use kill command to kill the process with the returned id or use following one liner script.
使用jps列出正在运行的java进程。该命令返回进程id和主类。您可以使用kill命令用返回的id杀死进程,或者使用下面的一个线性脚本。
kill $(jps | grep <MainClass> | awk '{print $1}')
MainClass is a class in your running java program which contains the main method.
MainClass是正在运行的java程序中的一个类,它包含主方法。
#4
0
pkill -f for whatever reason does not work for me. Whatever that does, it seems very finicky about actually grepping through what ps aux shows me clearly is there.
无论什么原因,pkill -f对我不起作用。不管那是什么,看起来很挑剔的是,通过ps,我清楚地看到了。
After an afternoon of swearing I went for putting the following in my start script:
在一个下午的咒骂之后,我开始在我的剧本中加入以下内容:
(ps aux | grep -v -e 'grep ' | grep MainApp | tr -s " " | cut -d " " -f 2 | xargs kill -9 ) || true
(ps aux | grep -v -e 'grep ' | grep MainApp | tr -s " | cut -d " - f2 | xargs kill -9) || true
#1
70
You can simply use pkill -f
like this:
你可以像这样简单地使用pkill -f:
pkill -f 'java -jar'
EDIT: To kill a particular java process running your specific jar use this regex based pkill command:
编辑:要杀死运行特定jar的特定java进程,请使用这个基于regex的pkill命令:
pkill -f 'java.*lnwskInterface'
#2
27
If you just want to kill any/all java processes, then all you need is;
如果您只想杀死任何/所有的java进程,那么您所需要的就是;
killall java
If, however, you want to kill the wskInterface process in particular, then you're most of the way there, you just need to strip out the process id;
但是,如果您想要特别地杀死wskInterface过程,那么您是大多数情况下的,您只需要去掉进程id;
PID=`ps -ef | grep wskInterface | awk '{ print $2 }'`
kill -9 $PID
Should do it, there is probably an easier way though...
应该这么做,也许有更简单的方法……
#3
0
Use jps to list running java processes. The command returns the process id along with the main class. You can use kill command to kill the process with the returned id or use following one liner script.
使用jps列出正在运行的java进程。该命令返回进程id和主类。您可以使用kill命令用返回的id杀死进程,或者使用下面的一个线性脚本。
kill $(jps | grep <MainClass> | awk '{print $1}')
MainClass is a class in your running java program which contains the main method.
MainClass是正在运行的java程序中的一个类,它包含主方法。
#4
0
pkill -f for whatever reason does not work for me. Whatever that does, it seems very finicky about actually grepping through what ps aux shows me clearly is there.
无论什么原因,pkill -f对我不起作用。不管那是什么,看起来很挑剔的是,通过ps,我清楚地看到了。
After an afternoon of swearing I went for putting the following in my start script:
在一个下午的咒骂之后,我开始在我的剧本中加入以下内容:
(ps aux | grep -v -e 'grep ' | grep MainApp | tr -s " " | cut -d " " -f 2 | xargs kill -9 ) || true
(ps aux | grep -v -e 'grep ' | grep MainApp | tr -s " | cut -d " - f2 | xargs kill -9) || true