windows - Find and kill a specific Java process from another Java App -


i have several java processes running on windows machine. have java process supposed monitor other processes , periodically kill or restart new ones.

if have java process running com.foo.main1 , 1 running com.foo.main2 - how can monitoring process find , kill main2 process?

update: have code can execute command line tasklist.exe , parse it, no matter do, see java.exe process, not class executing

update 2: not have ability install non-java programs.

it's going lot simpler using os-specific tools , using runtime.exec() run them, i'll try , give platform independent answer:


it might possible platform independently using attach api. comes jdk, use include tools.jar jdk on program's classpath.

to list of virtual machines on system, use virtualmachine.list(). can get/parse arguments virtual machine descriptor objects returned this.

the attach api allows load agents already-running java processes. since want kill java process, can write java agent runs system.exit() (or if really want dead use runtime.halt() instead) when agent loads.

once identify 1 want kill, attach , load killer agent (the agent has built jar file, accessible java process needs loaded into). shortly after agent attached process should die.

these links might also:

an oracle blog on attach api

package documentation java.lang.instrument (has detailed instructions on how build agent jar)


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -