16

I try to run

adb shell kill 5539

where 5539 is a process id found when running adb shell ps, but I get

/system/bin/sh: kill: 5539: Operation not permitted

How can I rectify my permissions?

This is the only adb documentation on kill:

kill [options]

Kill all processes associated with (the app's package name). This command kills only processes that are safe to kill and that will not impact the user experience. Options are:

--user | all | current: Specify user whose processes to kill; all users if not specified.

1

4 Answers 4

23

My methods:

Without root

adb shell am force-stop <package name>

I don't know how to do it with PID, kill <PID> and kill -9 <PID> don't work in my case

With root

I have also installed BusyBox to get more UNIX tools on my device

adb shell "su -c 'kill $(pidof <package name>)'"

or

adb shell "su -c 'kill <PID>'"
2
  • 1
    +1 nice answer, but adb shell "su -c kill 101" works for me (without '). Thanks :) Commented Mar 26, 2014 at 8:34
  • Although force-stop is useful, it is different to using kill. force-stop will change how Android OS treats that app. For example, push notifications are no longer delivered to the app. Commented Dec 5, 2021 at 17:35
12

You need to restart adb as root

This will give you permissions to kill the process.

$ adb root

$ adb shell kill 5539

2
1

I had the same problem with real device and I couldn't get root access.

When I run the command: adb root

I got the following error: adbd cannot run as root in production builds

I solved it by using the emulator. The emulator allows you to get root access.

Run your app on the emulator and then run these commands:

adb root

adb shell ps | grep com.your.app_package | awk '{print $2}' | xargs adb shell kill

The second command finds the PID of the app and kills it, if you don't know the PID. or you can use your command:

adb shell kill <PID>
0

I can only access the database of my emulator, not my device. Start the emulator using emulator -avd <device name> where you can find the device name by running android avd.

Not the answer you're looking for? Browse other questions tagged or ask your own question.