Runtime.exec() bug: hangs without providing a Process object

前端 未结 4 1219
不知归路
不知归路 2020-12-05 05:37

Whether I use this:

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

or that:

process = new ProcessBuilder()
               


        
相关标签:
4条回答
  • 2020-12-05 05:57

    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.

    0 讨论(0)
  • 2020-12-05 06:01

    Above solution didn't prove to be reliable in any ways, causing more issues on some devices!

    So I reverted back to the standard .exec() and kept digging...

    Looking at the child code that hangs, I noticed the child process will hang while trying to close all file descriptors inherited from the parent (except the one created within the exec() call) !

    So I search the whole app code for any BufferedReader/Writer and similar classes to make sure those would be closed when calling exec()!

    The frequency of the issue was considerably reduced, and actually never occured again when I removed the last opened file descriptor before calling exec().

    NB: Make sure SU binary is up-to-date, it can actually cause this issue too!

    Enjoy your search ;)

    0 讨论(0)
  • 2020-12-05 06:09

    Bug fix in Bionic was commited monthes ago, but it still hasn't been included in Android 4.0.4.

    0 讨论(0)
  • 2020-12-05 06:13

    I have the same problem on ICS (seem to works fine on Android < 4). Did you find a solution?

    A simple workaround could be to call the "exec" method in a dedicated thread with a timeout-join so that this situation could be "detected" (yes I know it's not very elegant...)

    0 讨论(0)
提交回复
热议问题