启动后台进程时,ADB进程会阻塞 [英] ADB process blocks when starting background process

查看:572
本文介绍了启动后台进程时,ADB进程会阻塞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过ADB在Android手机的后台运行Shell脚本。为简单起见,让它进入100睡眠状态:

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)

通过a单个adb命令行也被阻止:

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

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

可以正确运行脚本,但是adb调用会阻塞,直到 sleep 100完成。如果我CTRL-C退出adb,则睡眠进程将继续运行,因此nohup部分似乎正常工作。

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.

如何在生成子进程后使adb退出

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

推荐答案

adb shell'nohup sleep 10 2>不会强制杀死主机端的adb进程吗? / dev / null 1> / dev / null&'可以正常工作-启动该过程,并且不会阻塞。

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

这篇关于启动后台进程时,ADB进程会阻塞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆