Stop child process when parent process stops

久未见 提交于 2020-01-04 02:49:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!