Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ADB process blocks when starting background process

Tags:

android

shell

adb

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?

like image 209
Dennis Kempin Avatar asked Mar 22 '26 07:03

Dennis Kempin


1 Answers

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

like image 74
Alex P. Avatar answered Mar 24 '26 03:03

Alex P.