问题
In my android application, I create a child process with Runtime.getRuntime().exec().
But may be a situation, where a user kills my application, but the child process is still running. What I want is, when I kill the application, also kill the child process. How I can do it?
回答1:
I would
- Keep track of the processes created by my application.
- register a shutdown hook with the JVM through Runtime.getRuntime().addShutdownHook() that would be called when the application is shutdown and kill all the processes spawned, that were tracked in previous step.
来源:https://stackoverflow.com/questions/13243415/stop-child-process-when-parent-process-stops