ADB process blocks when starting background proces

2019-07-15 17:21发布

I am trying to run a shell script in the background on an Android phone via ADB. To simplify let's make it sleep 100:

$ adb shell
$ echo "nohup sleep 100&" > /data/local/tmp/test.sh
$ sh /data/local/tmp/test.sh
(does not block and returns to the shell immediately as expected. However:)
$ exit
(blocks until the sleep process is done)

Doing the same thing through a single adb command line is blocking as well:

$ adb shell sh /data/local/tmp/test.sh

Does run the script correctly, but the adb call blocks until 'sleep 100' is done. The sleep process keeps running if I CTRL-C out of adb, so the nohup part seems to be working correctly.

How can I get adb to exit after spawning the subprocess without forcefully killing the adb process on the host side?

1条回答
女痞
2楼-- · 2019-07-15 18:04

adb shell 'nohup sleep 10 2>/dev/null 1>/dev/null &' works as expected - starts the process and does not block.

查看更多
登录 后发表回答