停止子进程时,父进程停止 [英] Stop child process when parent process stops

查看:138
本文介绍了停止子进程时,父进程停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的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?

推荐答案

我会


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

  • 注册到<一个与JVM关闭挂钩href=\"http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29\"相对=nofollow> 调用Runtime.getRuntime()。addShutdownHook() 当应用程序被关闭,将被称为和杀死所有的进程产生了,那名跟踪在previous一步。

这篇关于停止子进程时,父进程停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆