Android ADB Shell ~ 如何列出进程的线程?

3

我正在尝试监控进程的线程列表。我希望可以通过ADB Shell查看它。我知道列出进程的方法:

adb shell ps -p

但是如何进一步查看该进程的线程?

使用:Android 4.4.2


如果只是为了调试目的,你最好只是在Android Studio中打开调试器视图/将调试器附加到正在运行的应用程序并在那里浏览线程,不是吗? - Thomas Keller
Thomas,这就足够了。谢谢。 - user2522885
在我的模拟器和Galaxy设备测试中,adb shell lsof -p <pid> 和 adb shell ps -T 这两个命令并没有像全球各地所建议的那样对我起作用。尽管我知道有线程在运行,但这两个命令都只显示外部进程,而不是我的线程。我赞同@ThomasKeller的观点,在可能的情况下使用调试会话。 - Matt Fiocca
2个回答

3

您可以使用 adb shell ps --help 查找所需选项。一种方法是使用 adb shell ps -T | grep <PID>,其中 <PID> 是线程 ID。您可以使用 adb shell ps -A 找到它。

在 Windows 10 上的示例:

PS C:\Users\languoguang> adb shell ps -A | findstr "system_server"
system        3107  1218 14800384 722996 do_epoll_wait      0 S system_server
PS C:\Users\languoguang> adb shell ps -T | findstr "3107" | findstr "Input"
system        3107  3332  1218 14800384 723868 do_epoll_wait      0 S InputDispatcher
system        3107  3333  1218 14800384 723868 do_epoll_wait      0 S InputReader
PS C:\Users\languoguang>

在旧版的安卓系统中,-T是用于线程的参数,而不是进程的参数。 - undefined

1
您要查找的命令是ps -t。这样就可以解决问题了。

2
不,adb shell ps -t 显示附加到 TTY 的进程。adb shell ps -T 显示线程。(请注意大写字母。) - Arto Bendiken
1
具有最小 ps 实现的旧版 Android 使用 -t 作为线程。 - hesham_EE

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接