当前位置:网站首页>Appium自动化测试基础 — adb shell 命令
Appium自动化测试基础 — adb shell 命令
2022-06-30 09:35:00 【测试-八戒】
Android系统是基于 Linux 内核的,也就是说Android系统的底层是Linux系统。所以 Linux 里的很多命令在 Android系统里也有相同或类似的实现,在 adb shell 里就可以调用。前面部分内容已经用到了 adb shell 命令,我们再来补充一下对adb shell 命令的认识。
提示:要在Android手机上执行的adb shell命令,就需要先root手机,而虚拟机是直接root的Android系统,所以直接可以在虚拟机上使用adb shell命令。
1、查看进程
命令:
adb shell ps输出示例:
USER PID PPID VSIZE RSS WCHAN PC NAME
root 1 0 8904 788 ffffffff 00000000 S /init
root 2 0 0 0 ffffffff 00000000 S kthreadd
...
u0_a71 7779 5926 1538748 48896 ffffffff 00000000 S com.sohu.inputmethod.sogou:classic
u0_a58 7963 5926 1561916 59568 ffffffff 00000000 S org.mazhuang.boottimemeasure
...
shell 8750 217 10640 740 00000000 b6f28340 R ps各列含义:
| 列名 | 含义 |
|---|---|
| USER | 所属用户 |
| PID | 进程 ID |
| PPID | 父进程 ID |
| NAME | 进程名 |
2、查看实时资源占用情况
命令:
adb shell top输出示例:
User 0%, System 6%, IOW 0%, IRQ 0%
User 3 + Nice 0 + Sys 21 + Idle 280 + IOW 0 + IRQ 0 + SIRQ 3 = 307
PID PR CPU% S #THR VSS RSS PCY UID Name
8763 0 3% R 1 10640K 1064K fg shell top
131 0 3% S 1 0K 0K fg root dhd_dpc
6144 0 0% S 115 1682004K 115916K fg system system_server
132 0 0% S 1 0K 0K fg root dhd_rxf
1731 0 0% S 6 20288K 788K fg root /system/bin/mpdecision
217 0 0% S 6 18008K 356K fg shell /sbin/adbd
...
7779 2 0% S 19 1538748K 48896K bg u0_a71 com.sohu.inputmethod.sogou:classic
7963 0 0% S 18 1561916K 59568K fg u0_a58 org.mazhuang.boottimemeasure
...各列含义:
| 列名 | 含义 |
|---|---|
| PID | 进程 ID |
| PR | 优先级 |
| CPU% | 当前瞬间占用 CPU 百分比 |
| S | 进程状态(R=运行,S=睡眠,T=跟踪/停止,Z=僵尸进程) |
| #THR | 线程数 |
| VSS | Virtual Set Size 虚拟耗用内存(包含共享库占用的内存) |
| RSS | Resident Set Size 实际使用物理内存(包含共享库占用的内存) |
| PCY | 调度策略优先级,SP_BACKGROUND/SPFOREGROUND |
| UID | 进程所有者的用户 ID |
| NAME | 进程名 |
top 命令还支持一些命令行参数,详细用法如下:
Usage: top [ -m max_procs ] [ -n iterations ] [ -d delay ] [ -s sort_column ] [ -t ] [ -h ]
-m num 最多显示多少个进程
-n num 刷新多少次后退出
-d num 刷新时间间隔(单位秒,默认值 5)
-s col 按某列排序(可用 col 值:cpu, vss, rss, thr)
-t 显示线程信息
-h 显示帮助文档3、查看进程 UID
有两种方案:
adb shell dumpsys package <packagename> | grep userId=
如:
$ adb shell dumpsys package org.mazhuang.guanggoo | grep userId=
userId=103942、 通过 ps 命令找到对应进程的 pid 之后 adb shell cat /proc/<pid>/status | grep Uid
如:
$ adb shell
gemini:/ $ ps | grep org.mazhuang.guanggoo
u0_a394 28635 770 1795812 78736 SyS_epoll_ 0000000000 S org.mazhuang.guanggoo
gemini:/ $ cat /proc/28635/status | grep Uid
Uid: 10394 10394 10394 10394
gemini:/ $4、其它adb shell 命令
如下是其它常用命令的简单描述,前文已经专门讲过的命令不再额外说明:
| 命令 | 功能 |
|---|---|
| cat | 显示文件内容 |
| cd | 切换目录 |
| chmod | 改变文件的存取模式/访问权限 |
| df | 查看磁盘空间使用情况 |
| grep | 过滤输出 |
| kill | 杀死指定 PID 的进程 |
| ls | 列举目录内容 |
| mount | 挂载目录的查看和管理 |
| mv | 移动或重命名文件 |
| ps | 查看正在运行的进程 |
| rm | 删除文件 |
| top | 查看进程的资源占用情况 |
和Linux系统中的命令基本上是一样的。
重点:配套学习资料和视频教学
那么在这里我也精心准备了上述大纲的详细资料在下方链接如下


边栏推荐
- Simple redis lock
- 【ARK UI】HarmonyOS ETS的启动页的实现
- MCU firmware packaging Script Software
- DataTableToModelList实体类
- Microsoft. Bcl. Async usage summary -- in Net framework 4.5 project Net framework version 4.5 and above can use async/await asynchronous feature in C 5
- Shenhe thermomagnetic: Super fusion dual active cluster solution for MES system
- Mysql database learning 1
- Returnjson, which allows more custom data or class names to be returned
- Oracle cross database replication data table dblink
- About the smart platform solution for business hall Terminal Desktop System
猜你喜欢

MySQL-- Entity Framework Code First(EF Code First)

How to reduce the delay in live broadcast in the development of live broadcast source code with goods?

Read the difference and connection between hyperfusion and private cloud

IDC released the report on China's software defined storage and hyper convergence market in the fourth quarter of 2020, and smartx hyper convergence software ranked first in the financial industry

Principle and implementation of small program hand-held bullet screen (uni APP)

Machine learning note 9: prediction model optimization (to prevent under fitting and over fitting problems)

八大排序(二)
![Train an image classifier demo in pytorch [learning notes]](/img/a5/fc14ee9dda1ec3e17b0ae2bda84d86.png)
Train an image classifier demo in pytorch [learning notes]

MySQL knowledge summary (useful for thieves)

P. Summary of NP, NPC, NP hard and other issues
随机推荐
机器学习笔记 九:预测模型优化(防止欠拟合和过拟合问题发生)
基于Svelte3.x桌面端UI组件库Svelte UI
Principle and implementation of small program hand-held bullet screen (uni APP)
单片机 MCU 固件打包脚本软件
Flutter 中的 ValueNotifier 和 ValueListenableBuilder
[ubuntu-mysql 8 installation and master-slave replication]
Difference between bow and cbow
JVM tuning tool commands (notes)
【新书推荐】Cleaning Data for Effective Data Science
Flume learning III
MySQL-- Entity Framework Code First(EF Code First)
The present situation and challenge of the infrastructure of Yiwen parsing database
Upgrade log4j2 to 2.17.1 stepped pit
Cloud native database
MySQL optimization
Oracle cross database replication data table dblink
近期学习遇到的比较问题
【Ubuntu-redis安装】
Numpy (constant)
Pytorch graduate warm LR installation