Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the process id of a running Java process on Windows? And how to kill the process alone?

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

like image 357
Muthu Kumar Avatar asked Oct 23 '12 07:10

Muthu Kumar


People also ask

How do I kill a specific process in Windows Java?

Using taskkill, you can kill a process based on window title using a filter. If the window title has quotes in it, you can escape the nested quotes with a backslash ( \ ). You can use tasklist in a similar manner to search for a task based on its window title.

How can a Java program gets its own process id?

getRuntimeMXBean(). getName() looks like the best (closest) solution, and typically includes the PID. It's short, and probably works in every implementation in wide use. On linux+windows it returns a value like "12345@hostname" ( 12345 being the process id).


2 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% 
like image 129
Ingo Kegel Avatar answered Sep 25 '22 17:09

Ingo Kegel


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

like image 40
cete3 Avatar answered Sep 25 '22 17:09

cete3