Stop the child process when the parent process stops

In my Android app, I create a child process with Runtime.getRuntime().exec() .

But there may be a situation where the user kills my application, but the child process is still running. I want, when I kill the application, also kill the child process. How can i do this?

+3
source share
1 answer

I'd

  • Follow the processes created by my application.
  • register the stop binding with the JVM via Runtime.getRuntime().addShutdownHook() , which will be called when the application terminates and destroys all the spawned processes that were tracked in the previous step.
+1
source

Source: https://habr.com/ru/post/943450/


All Articles