Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for a java process in one jvm to kill/stop another java process in another jvm?

If so, how can I find out which process is it(out of all the others on the system) and how do I kill it such that its shutdownhook gets executed?

Reason I want to do this is because I want to implement something like apache start, apache stop whereby after invoking apache start or apache stop, a server process starts or stops in the background and I get the command or bash prompt back; this is suppose to work on both linux and windows.

like image 579
shawn Avatar asked Feb 13 '12 06:02

shawn


2 Answers

It's possible, but it will be operating system specific. There's nothing in the JVM that automatically gives you access to kill other VMs.

You'll either need to call your operating system's kill command (or equivalent) or write some native code.

It can be done, and if you're only going to run on unix-like systems, then your best option would be to write a shell script that does what you want, and then execute it with ProcessBuilder and friends.

like image 121
Tim Avatar answered Sep 28 '22 12:09

Tim


U can think about opening a service on servant side ,which is for close itself, to be handled by the master application.

On the other hand, if u do not want to do it, u need to find a way to get the processes of a jvm instance. If u just want to kill jvm, it would be easy but for a specific process. U need some help I think, like this:

link

Hope it works for u

like image 45
Neron Avatar answered Sep 28 '22 14:09

Neron