Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop external program when Java program is stopped

I'm executing an external program which runs alongside Java using this:

Process p = Runtime.getRuntime().exec("/path/to/binary");

When I stop the Java application, the external program continues to run but I want this to stop too.

like image 500
Matt Avatar asked Jun 03 '11 20:06

Matt


1 Answers

To trigger the shutdown, you could add a shutdown hook to your Java application. See Runtime.addShutdownHook().

To effect the shutdown, you could either communicate to the external process a request to stop gracefully, or call Process.destroy()

like image 50
Andy Thomas Avatar answered Sep 22 '22 13:09

Andy Thomas