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).

- 78,363
- 46
- 261
- 468

- 480
- 1
- 6
- 8
-
check following [enter link description here][1] [1]: http://stackoverflow.com/questions/8435952/how-to-get-pid-from-command-line-filtered-by-username-and-imagename – mostafa.S Oct 23 '12 at 08:06
9 Answers
You can use the jps
utility that is included in the JDK 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%

- 46,523
- 10
- 71
- 102
-
7`jps` tool is now included in **JDK/bin** directory. I also recommend to use `-l` option, which outputs the full package name for the application's main class, which might be helpful. – jsosnowski Sep 04 '15 at 07:48
-
4
-
and it's not allowed to redistribute jps.exe outside of bundled JDK - if you get this fancy idea like myself :( - therefore WMIC solution below is the real winner for me – hello_earth Nov 23 '20 at 17:19
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 :

- 647
- 6
- 19
-
1Your Windows Task Manager window is in German, but your it show full answer: We may find java process on list, then we have its PID number and in `Command line` (here on image _Befehlszeile_) we see full command, which helps us to discriminate which _java_ process to kill. – jsosnowski Sep 04 '15 at 07:42
-
1To edit column list, just right-click on any column header (in Details tab) and choose `Select column` option. – jsosnowski Sep 04 '15 at 07:44
This will work even when there are multiple instance of jar is running
wmic Path win32_process Where "CommandLine Like '%yourname.jar%'" Call Terminate

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

- 2,664
- 8
- 38
- 64
-
-
Please accept the answer if it helps :) see http://meta.stackexchange.com/questions/23138/how-to-accept-the-answer-on-stack-overflow – khan Oct 23 '12 at 08:10
In windows, we can use the PowerShell to list the java running process. Then using the process id we can kill the process. Please find the below commands that needs to be executed in the PowerShell.
To list the Java Process.
ps | Where-Object -Property ProcessName -EQ -Value 'Java'
To kill the java process with specific id.
Stop-Process <PID>
The above approach worked for me.

- 1,583
- 2
- 15
- 19
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"
);

- 404
- 4
- 8
In windows XP and later, there's a command: tasklist that lists all process id's.
For killing a process in Windows, see:
Really killing a process in Windows | Stack Overflow
You can execute OS-commands in Java by:
Runtime.getRuntime().exec("your command here");
If you need to handle the output of a command, see example: using Runtime.exec() in Java

- 2,955
- 2
- 24
- 34
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.
-
taskkill doesn't work: error: search filter is not recognized (something about it). But thanks for `start "MyProgramName"` – Mikhail Ionkin Oct 02 '19 at 11:03
-