0

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
BoB3R
  • 41
  • 5
  • 1
    Killing by PID is a requirement ? If not, open a socket and listening for a shutdown command is a much more cleaner solution. – PeterMmm Jan 02 '17 at 09:56
  • Hello, no it's not. Thanks for the lead! – BoB3R Jan 02 '17 at 10:05
  • 1
    PIDs are given by kernel. Add a no-op identifier argument when launching applications "java -classpath ./lib com.package.MyApp key1=val1 key2=val2 processidenfier=abcxyz123". List processes with a full argument list, kill one by one with PID skipping an active java.exe process. Or use JNI/JNA to read current pid http://stackoverflow.com/questions/35842/how-can-a-java-program-get-its-own-process-id – Whome Jan 02 '17 at 10:10

1 Answers1

0

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%'"
BoB3R
  • 41
  • 5