PID java application and kill

344 Views Asked by At

I would like to assign PID to my java application (if it's possible), and kill every other javaw.exe.

Runtime.getRuntime().exec("taskkill /F /IM javaw.exe");

or PID

Runtime.getRuntime().exec("taskkill /F /PID <ID>");

I know this will kill all javaw.exe, but I need my application still up and running.

It should kill specific java application, but they are having random PID's assign. I though the easiest way would be close all java applications running except mine.

1

There are 1 best solutions below

0
On

I've did it a little bit different. I've used "wmic", to list all the java process and PID at the end. I am taking the the last numbers and killing them.

wmic process where "name like '%javaw%'"