How to kill a process/package from ADB in Android

This article will introduce how to kill a process/package from ADB command in Android.

1. "adb shell am force-stop"

The following command forcibly stops and changes the com.google.android.youtube package to a stop state. During this process, the app's process will be terminated.

$ adb shell am force-stop com.google.android.youtube

Note that stop state means that the app couldn't get any broadcast until it's changed to not stop state

2. "adb shell kill PACKAGE_NAME"

If you know the PID of a package, then you can terminate it with the kill command.

2.1 How to get the PID of a package with package name

The following command prints the pid of the com.google.android.youtube package. 5862 is the PID of Youtube.

$ adb shell pidof com.google.android.youtube
5862

Note that If the App is not running, nothing will be output because there are no running processes.

2.2 Killing the process of PID

The following command will kill PID 5862. But, It will fail due to permission issues if run with an unrooted device.

$ adb shell kill -9 5862
/system/bin/sh: kill: 5862: Operation not permitted

If you root it as follows, the process will end when you enter the command again.

$ adb root
restarting adbd as root

$ adb shell kill -9 5862

To make sure the package is killed, you can check the PID by the following command. Nothing will be outputted if it was killed successfully.

$ adb shell pidof com.google.android.youtube

Related Posts

codechachaCopyright ©2019 codechacha