Stop an external program when a Java program stops

I am running an external program that runs next to Java using this:

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

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

+5
source share
2 answers

To start shutdown, you can add the shutdown application to it. See Runtime.addShutdownHook () .

To shutdown, you can either pass a request to cease grace to an external process, or call Process.destroy ()

+4
source

All Articles