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

问题描述

不管我用这样的:

process = Runtime.getRuntime().exec("logcat -d time");

process = new ProcessBuilder()
              .command("logcat", "-d", "time")
              .redirectErrorStream(true)
              .start();

我得到相同的结果:它常常挂EXEC(),或在启动()调用,不管是什么我试图做!运行该线程甚至不能用了Thread.interrupt中断()!子进程肯定是开始,如果杀了上面的命令返回。

I get the same results: it often hangs within the exec() or start() call, no matter what I tried to do!The thread running this cannot even be interrupted with Thread.interrupt()! The child process is definitely started and if killed the above commands return.

这些要求可能会失败的第一次尝试,所以没有办法读取它们的输出!我也可以用一个简单的苏-c杀XXX命令行,同样的结果!

These calls may fail on first attempt, so THERE IS NO WAY TO READ THEIR OUTPUT! I can also use a simple "su -c kill xxx" command line, same result!

编辑:开始调试java_lang_ProcessManager.cpp文件中的NDK项目,一些调试日志!因此,这里是我发现至今,叉()后父做到这一点:

Started debugging the java_lang_ProcessManager.cpp file in an NDK project with some debugging logs! So here is what I found so far, after the fork() the parent does this:

int result;
int count = read(statusIn, &result, sizeof(int));            <- hangs there
close(statusIn);

虽然子进程不应该阻止它:这就是孩子做(如果在所有的启动!):

    // Make statusOut automatically close if execvp() succeeds.
    fcntl(statusOut, F_SETFD, FD_CLOEXEC);                      <- make the parent will not block

    // Close remaining unwanted open fds.
    closeNonStandardFds(statusOut, androidSystemPropertiesFd);  <- hangs here sometimes

    ...

    execvp(commands[0], commands);

    // If we got here, execvp() failed or the working dir was invalid.
    execFailed:
        int error = errno;
        write(statusOut, &error, sizeof(int));
        close(statusOut);
        exit(error);

孩子可能会失败,2重现的原因:1子code未运行,但父母认为这是!2-子块上        closeNonStandardFds(statusOut,androidSystemPropertiesFd);

The child can fail for 2 reproducible reasons: 1- child code is not running, but the parent believes it is!2- child blocks on closeNonStandardFds(statusOut, androidSystemPropertiesFd);

在这两种情况下的僵局父读(statusIn ...)结束!和一子过程是左死(和不能被访问,PID未知,没有过程对象)!

In either case the read(statusIn...) in the parent ends in deadlock! and a child process is left dead (and cannot be accessed, pid unknown, no Process object)!

推荐答案

此问题在的,但不是在的,我想它永远不会被固定在ICS。

This problem is fixed in Jelly Bean (Android 4.1) but not in ICS (4.0.4) and I guess it will never be fixed in ICS.

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

10-24 07:36