停止子进程时,父进程停止

停止子进程时,父进程停止

问题描述:

在我的Andr​​oid应用程序,我创建一个子进程调用Runtime.getRuntime()。EXEC()

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?

我会


  • 跟踪我的应用程序创建的过程。

  • 注册到 调用Runtime.getRuntime()。addShutdownHook() 当应用程序被关闭,将被称为和杀死所有的进程产生了,那名跟踪在previous一步。