[英]adb command to kill background processes using python
I am doing android automation using python code and I am new to it.我正在使用 python 代码进行 android 自动化,我是新手。
I am using a background process which will be connected to frontend application in an android device.我正在使用一个后台进程,该进程将连接到 Android 设备中的前端应用程序。
I want to kill the process:我想终止进程:
I have the adb command for killing the application as我有用于终止应用程序的 adb 命令
adb shell am kill-all
Now I want to use this command to kill all the process irrespective of whether they are running in background or foreground.现在我想使用这个命令来终止所有进程,而不管它们是在后台还是在前台运行。
Can someone help how to do it in python?有人可以帮助如何在python中做到这一点吗?
Alternatively i used the following command或者我使用以下命令
cmd="adb shell pm clear <com.packagename>"
process = subprocess.check_output(cmd, shell=True,stderr=subprocess.PIPE)
This worked and i an able to kill the particular process.这有效,我能够终止特定进程。 But thats not I am looking for.但这不是我要找的。 I need to kill all such processes which are running in background.我需要杀死所有在后台运行的进程。
Alternatively, you can use a small logic here.或者,您可以在此处使用一个小逻辑。 Execute a command with lists the background processes running.执行一个命令,列出正在运行的后台进程。 use a loop to traverse through the list of all the active processes and apps.使用循环遍历所有活动进程和应用程序的列表。
then use the following command to kill them one by one.然后使用以下命令将它们一一杀死。
cmd="adb shell pm clear" + bacgoundProcess;
process = subprocess.check_output(cmd, shell=True,stderr=subprocess.PIPE);
Hope this works for you.希望这对你有用。
You can try the dumpsys for list out all the services runing您可以尝试使用 dumpsys 列出所有正在运行的服务
adb shell dumpsys -l
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.