adb之ps命令用法

目录


前言

在adb shell终端,输入 ps,可查看手机当前所有的进程状态,其中ps的英文全称是Process Status。 ps命令对于分析系统异常情况时都是必备的技能,需要通过这个简单命令来查看系统真实的状态。

一、命令参数

  • -A: 显示所有进程,包括与控制终端无关的进程。
  • -a: 显示所有终端(与 -d 相反)。
  • -d: 显示所有进程,但不包括会话领导者。
  • -e: 显示所有进程(与 -A 选项相同)。
  • -g: 以进程组来显示进程。
  • -G: 以实际组名来显示进程(在sgid之前)。
  • -p: 根据指定的PID来显示进程。
  • -P: 根据父PID来显示进程。
  • -s: 在会话ID中显示进程。
  • -t: 附加到指定的TTY(终端)上的进程。
  • -T: 显示线程信息。
  • -u: 根据指定的用户名来显示进程。
  • -U: 根据实际用户名来显示进程(在suid之前)。

上面的参数可根据需要自由组合,比如查看系统中所有进程的基本信息:
adb shell ps -A

查看特定进程的线程信息(以PID为例,可以在ps命令或其他命令中获取特定进程的PID):
adb shell ps -T < PID>

c 复制代码
1|trinket:/ # ps -T 31144
USER           PID   TID  PPID     VSZ    RSS WCHAN            ADDR S CMD
u0_a115      31144 31144   597 5707888  96156 SyS_epoll+          0 S mservice:remote
u0_a115      31144 31150   597 5707888  96156 futex_wai+          0 S Jit thread pool
u0_a115      31144 31155   597 5707888  96156 do_sigtim+          0 S Signal Catcher
u0_a115      31144 31156   597 5707888  96156 poll_sche+          0 S ADB-JDWP Connec
u0_a115      31144 31157   597 5707888  96156 futex_wai+          0 S HeapTaskDaemon
u0_a115      31144 31158   597 5707888  96156 futex_wai+          0 S ReferenceQueueD
u0_a115      31144 31159   597 5707888  96156 futex_wai+          0 S FinalizerDaemon
u0_a115      31144 31160   597 5707888  96156 futex_wai+          0 S FinalizerWatchd
u0_a115      31144 31161   597 5707888  96156 binder_io+          0 S Binder:31144_1
u0_a115      31144 31162   597 5707888  96156 binder_io+          0 S Binder:31144_2
u0_a115      31144 31165   597 5707888  96156 binder_io+          0 S Binder:31144_3
u0_a115      31144 31173   597 5707888  96156 futex_wai+          0 S Profile Saver
u0_a115      31144 31175   597 5707888  96156 binder_io+          0 S HwBinder:31144_
u0_a115      31144 31232   597 5707888  96156 binder_io+          0 S Binder:31144_4
u0_a115      31144 31233   597 5707888  96156 SyS_epoll+          0 S queued-work-loo

查看所有普通应用程序,老版本android是单用户的,所以用户普通进程的user都是以u0开头的,google有意把android发展成支持多用户的,现在已经有u1, u2_等等的用户名,另外普通app的uid是从10000开始:

c 复制代码
ps -A |grep u0
u0_a111       2036   597 6654872 199308 SyS_epoll_wait      0 S com.android.systemui
u0_a112       2401   597 6294320 164404 SyS_epoll_wait      0 S com.android.launcher3
u0_a56        2477   597 5758552  91156 SyS_epoll_wait      0 S android.ext.services
u0_a130       2560   597 5770632 109984 SyS_epoll_wait      0 S com.android.inputmethod.latin
u0_a89        3035   597 5770064  95024 SyS_epoll_wait      0 S com.qualcomm.qti.sva
u0_a97        3090   597 5717908  89052 SyS_epoll_wait      0 S .pasr
u0_a119       3131   597 5735684  92332 SyS_epoll_wait      0 S com.qualcomm.qti.services.systemhelper:systemhelper_service
u0_a88        3353   597 5651104  83940 SyS_epoll_wait      0 S com.android.smspush
u0_a48        3652   597 5803580 103868 SyS_epoll_wait      0 S android.process.media
u0_a118       4427   597 5704704  83668 SyS_epoll_wait      0 S com.qualcomm.qti.callenhancement
u0_a135       5277   597 5722432  87816 SyS_epoll_wait      0 S com.qualcomm.telephony
u0_a58       11871   597 6139768 160692 SyS_epoll_wait      0 S org.codeaurora.snapcam
u0_a138      12967   597 5633764  89704 SyS_epoll_wait      0 S org.chromium.webview_shell
u0_a168      13165   597 5678620 103000 SyS_epoll_wait      0 S com.quectel.cardiagnosis
u0_a162      13199   597 5844304 180444 SyS_epoll_wait      0 S com.example.hxplay
u0_a144      13233   597 5835764 146244 SyS_epoll_wait      0 S com.henry.basic
u0_a63       19299   597 5679996  82448 SyS_epoll_wait      0 S com.android.cellbroadcastreceiver
u0_a81       19936   597 5679012  86284 SyS_epoll_wait      0 S com.android.printspooler
u0_a51       19949   597 5722976  95068 SyS_epoll_wait      0 S com.android.providers.calendar
u0_a44       28312   597 5748860 106720 SyS_epoll_wait      0 S android.process.acore
u0_a160      28563   597 5748916 119836 SyS_epoll_wait      0 S com.android.audiotest
u0_a140      28725   598 1879448  90096 SyS_epoll_wait      0 S com.android.webview:webview_service
u0_a52       28851   597 5802572 138512 SyS_epoll_wait      0 S com.android.permissioncontroller
u0_a106      30983   597 5771068  99520 SyS_epoll_wait      0 S com.android.dialer
u0_a115      31144   597 5707888  96156 SyS_epoll_wait      0 S com.qualcomm.qti.seccamservice:remote

二、输出结果含义

例如,在手机输出如下命令:(20671是某个进程pid)

c 复制代码
 ps -A |grep -E "NAME| 13199 "
USER           PID  PPID     VSZ    RSS WCHAN            ADDR S NAME
u0_a162      13199   597 5844304 180444 0     0 S com.example.hxplay

结果分析:

字段 含义
USER 所有者用户的用户名,表示运行进程的用户。 u0_a162
PID 进程ID(Process ID),唯一标识每个进程的数字。 13199
PPID 父进程ID(Parent Process ID),标识创建当前进程的父进程的ID。 597
VSZ 虚拟内存大小(Virtual Memory Size),进程当前使用的虚拟内存大小(以KB为单位)。 5844304
RSS 常驻集大小(Resident Set Size),表示进程占用的物理内存大小(以KB为单位)。 180444
WCHAN 当前等待的内核函数(The name of the kernel function in which the process is sleeping)。 0
ADDR 内存地址(Memory Address),进程的内存地址。 0
S 进程状态,表示进程的当前状态,此处为"S"表示休眠(sleeping)状态。 S
NAME 命令名(Command Name),表示进程的名称或命令。 com.example.hxplay

注: WCHAN值为0代表进程处于运行态;否则代表内核地址(休眠态)。

参考链接:

adb中ps命令的详解

相关推荐
。puppy1 天前
MySQL 远程登录实验:通过 IP 地址跨机器连接实战指南
android·adb
q***44811 天前
mysql配置环境变量——(‘mysql‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件解决办法)
数据库·mysql·adb
q***3752 天前
MySQL输入密码后闪退?
数据库·mysql·adb
杨DaB2 天前
【MySQL】03 数据库的CRUD
数据库·mysql·adb
Lxinccode2 天前
python(62) : 环境变量管理
android·python·adb·环境变量·变量管理
m0_731048202 天前
adb 命令的介绍与使用
adb
q***64972 天前
mysql的主从配置
android·mysql·adb
q***49862 天前
MySQL root用户密码忘记怎么办(Reset root account password)
数据库·mysql·adb
m0_731048202 天前
MuMu模拟器,配置ADB端口
adb
2501_941225683 天前
C++高性能数据库访问与连接池实战分享:大规模数据处理与优化策略经验
adb