How to find the process id of a running Java proce

2019-03-09 18:48发布

I want to kill the particular Java process in Windows, like in Linux (ps -aux to get processid and then kill processid to kill the process).

7条回答
迷人小祖宗
2楼-- · 2019-03-09 19:15

You can also find the PID of a java program with the task manager. You enable the PID and Command Line columns View -> Select Columns and are then able to find the right process.

Your result will be something like this : enter image description here

查看更多
▲ chillily
3楼-- · 2019-03-09 19:16

This will work even when there are multiple instance of jar is running

wmic Path win32_process Where "CommandLine Like '%yourname.jar%'" Call Terminate
查看更多
Viruses.
4楼-- · 2019-03-09 19:20

This is specific to Windows. I was facing the same issue where I have to kill one specific java program using taskkill. When I run the java program, tasklist was showing the same program with Image name set as java.exe. But killing it using taskkill /F java.exe will stop all other java applications other than intended one which is not required.

So I run the same java program using:

start "MyProgramName" java java-program..

Here start command will open a new window and run the java program with window's title set to MyProgramName.

Now to kill this java-program use the following taskkill command:

taskkill /fi "MyProgramName"

Your Java program will be killed only. Rest will be unaffected.

查看更多
男人必须洒脱
5楼-- · 2019-03-09 19:27

The solution I found is very simple. Use Window's WMIC & Java's Runtime to locate & kill the process.

Part 1: You need to put some sort of identifier into your app's startup command line. E.g. something like:

String id = "com.domain.app";

Part 2: When you run your app, make sure to include the string. Let's say you start it from within Java, do the following:

Runtime.getRuntime().exec(
   "C:\...\javaw.exe -cp ... -Dwhatever=" + id + " com.domain.app.Main"
);

Part 3: To kill the process, use Window's WMIC. Just make sure you app was started containing your id from above:

Runtime.getRuntime().exec(
  "wmic process Where \"CommandLine Like '%" + id + "%'\" Call Terminate"
);
查看更多
Summer. ? 凉城
6楼-- · 2019-03-09 19:28

After setting the path of your jdk use JPS.Then You can eaisly kill it by Task Manager
JPS will give you all java processes

查看更多
趁早两清
7楼-- · 2019-03-09 19:33

You can use the jps utility that is included in the JRE to find the process id of a Java process. The output will show you the name of the executable JAR file or the name of the main class.

Then use the Windows task manager to terminate the process. If you want to do it on the command line, use

TASKKILL /PID %PID%
查看更多
登录 后发表回答