简体   繁体   中英

adb command to kill background processes using python

I am doing android automation using python code and I am new to it.

I am using a background process which will be connected to frontend application in an android device.

I want to kill the process:

I have the adb command for killing the application as

    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?

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

adb shell dumpsys -l

Adb dumsys Information

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM