Search code examples
javawindowskill-process

Kill a java process using its Name and not PID


In my java program I want to kill a process named "DummyBroker"(which is another java program). i could kill it using TaskKill but it needs PID of the process. So how can i fetch the pid for a specific java process and then kill it?


Solution

  • Finally found a easy solution here

    jps - Java Virtual Machine Process Status Tool , can be used for killing a java process with its name.

    for /f "tokens=1" %i in ('C:\java\jdk-7u45-windows-x64\bin\jps -m ^| find "DummyBroker"') do ( taskkill /F /PID %i )
    

    We can add above in batch file and simply call the batch file from java program.