的Runtime.exec()BUG:挂起 [英] Runtime.exec() bug: hangs

查看:172
本文介绍了的Runtime.exec()BUG:挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序正在检查苏,因为它是必要的应用程序工作的第一件事情。虽然有时工作,经常打字后killall的的packageName 的终端。我做了一个简单的测试应用程序,我不能让它每次都工作。
code它发生在哪里:

First thing my app does is checking for "su" since it's necessary for the app to work. Even though it sometimes work, often after typing "killall packageName" in the terminal. I've done a simple test application and I can't get it to work every time. Code where it happens:

String[] args = new String[] { "su" };
Log.v(TAG, "run(" + Arrays.toString(args) + ")");
FutureTask<Process> task = new FutureTask<Process>(new Callable<Process>() {
    @Override
    public Process call() throws Exception {
        return Runtime.getRuntime().exec(args);
    }
});
try {
    Executors.newSingleThreadExecutor().execute(task);
    return task.get(10, TimeUnit.SECONDS);
} catch (Throwable t) {
    task.cancel(true);
    throw new IOException("failed to start process within 10 seconds", t);
}

完整的项目: https://github.com/chrulri/android_testexec

由于这个程序确实没有什么比在首位运行的exec()多了,我无法关闭任何previously打开的文件描述符作为另一个计算器问题中提到:<一href=\"http://stackoverflow.com/a/11317150/1145705\">http://stackoverflow.com/a/11317150/1145705

Since this app does nothing more than running exec() in the first place, I cannot close any previously opened file descriptors as mentioned in another stackoverflow question: http://stackoverflow.com/a/11317150/1145705

PS:我运行Android 4.0.3 / 4.0.4在不同的设备

PS: I run Android 4.0.3 / 4.0.4 on different devices.

推荐答案

3c71说得对打开的文件描述符。就我而言,这是AdMob的SDK造成,因为它是有时问题(重新)加载从网站的广告在森那一次我试图调用exec(..)留下我挂在一个僵局。

3c71 was right about open file descriptors. In my case, it was the AdMob SDK which caused the problems since it was sometimes (re-)loading the Ads from the web at the sime time I tried to call exec(..) leaving me hanging in a deadlock.

我的解决办法是ONCE fork一个苏的进程,并重新使用它的所有命令和加载广告之后,分叉这一进程。

My solution is to fork a "su" process ONCE and reuse it for all commands and load the Ads AFTER forking that process.

这篇关于的Runtime.exec()BUG:挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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