挂起android进程,Runtime.exec() Bug: 挂起不提供进程对象_android_开发99编程知识库

是否使用:process = Runtime.getRuntime().exec("logcat -d time");

或者:process = new ProcessBuilder()

. command("logcat","-d","time")

. redirectErrorStream(true)

. start();

我得到了同樣的結果: 它通常掛在 exec() 或者 start() 調用中,無論我怎麼做 ! 運行這裡線程的線程甚至不能用 Thread.interrupt() 中斷 ! 子進程絕對啟動,如果殺死上面的命令返回。

這些調用在第一次嘗試時可能會失敗,因此無法讀取它們的輸出 ! 我也可以使用一個簡單的"su -c殺死 xxx"命令行,同樣的結果 !

編輯:使用一些調試日誌在NDK項目中開始調試 java_lang_ProcessManager.cpp 文件 ! 這是我到目前為止發現的,在 fork() 之後,父對象執行以下操作:int result;

int count = read(statusIn, &result, sizeof(int));

close(statusIn);

儘管子進程不應該阻塞它: 這就是孩子做的( 如果開始 ): !//Make statusOut automatically close if execvp() succeeds.

fcntl(statusOut, F_SETFD, FD_CLOEXEC);

//Close remaining unwanted open fds.

closeNonStandardFds(statusOut, androidSystemPropertiesFd);

. . .

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 - 子代碼沒有運行,但是父代碼認為它是 ! 2 - closeNonStandardFds ( statusOut,androidSystemPropertiesFd ) 上的子塊;

在任何情況下,父進程中的read(statusIn...) 都處於死鎖狀態 ! 還有一個子進程是死( 並且無法訪問,pid未知,沒有進程對象) !

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值