【问题标题】:Start a process in background from adb shell without attaching the process to the terminal in Android从 adb shell 在后台启动一个进程,而不将该进程附加到 Android 中的终端
【发布时间】:2026-01-25 15:05:01
【问题描述】:

我有一个简单的问题。 我想使用 adb shell 在安卓手机上启动/运行程序文件。
我的程序位于 /system/bin 文件夹中,并且具有 root 权限。

我想在我的命令提示符下以adb shell runme 3000000 > logs.txt 运行这个程序,但它不应该阻塞终端,它应该在后台运行。

我不能使用 screen/disown/nohup 来解决我的问题,因为 android 没有这一切。
我试过了 adb shell "runme >logs.txt &" 但没用。

当我发出命令时
adb shell
# runme 3000000 > logs.txt &
它运行良好,当我退出终端/断开设备然后再次连接到系统时。
adb shell ps | grep runme 显示进程仍在后台运行。

谢谢

【问题讨论】:

  • 将您的 adb shell 命令包装在一些 python 脚本中,该脚本会产生一个新线程。
  • adb shell里面有python吗?

标签: android shell adb


【解决方案1】:

Busybox 有 nohup 小程序,在 Android 中运行良好

【讨论】:

    最近更新 更多