简体   繁体   English

在 Android 中从 shell 终止进程

[英]Kill processes from shell in Android

I try to find some way to kill unnecessary services/processes in Android from shell.我试图找到一些方法来从 shell 中杀死 Android 中不必要的服务/进程。 The problem is that after killing the process it starts again after few seconds!问题是,在终止进程后,它会在几秒钟后再次启动!

for example I tried to kill batterywarning, but it keep starting again:例如我试图杀死 batterywarning,但它又开始了:

root@w812a_kk:/ # ps  | grep batteryw
shell     17986 1     1044   364   c00601dc b6e9f094 S /system/bin/batterywarning
1|root@w812a_kk:/ # ps  | grep batteryw
shell     17781 1     1044   364   c00601dc b6ee6094 S /system/bin/batterywarning
root@w812a_kk:/ # busybox killall batterywarning
root@w812a_kk:/ # ps  | grep batteryw
1|root@w812a_kk:/ # ps  | grep batteryw
shell     17986 1     1044   364   c00601dc b6e9f094 S /system/bin/batterywarning

I did find several methods to kill service/process in the following link, yet the process is starting again.我确实在以下链接中找到了几种终止服务/进程的方法,但该进程又开始了。

Android ADB stop application command like "force-stop" for non rooted device . Android ADB 停止应用程序命令,如非 root 设备的“force-stop”

Is it something that can only be done in init.rc?是不是只能在 init.rc 里做?

Thanks,谢谢,

This service is probably started as STICKY - it will be automatically restarted by OS after some predefined timeout.此服务可能以 STICKY 启动 - 它将在一些预定义的超时后由操作系统自动重新启动。

You can check it by pulling the logcat from the device and grepping it for the name of the service you attempted to kill:您可以通过从设备中拉出 logcat 并在其中查找您试图终止的服务的名称来检查它:

$ adb logcat -d > logcat.txt
$ grep -C 5 -i batterywarning logcat.txt

If you see something along the lines scheduling restart of crashed service in X seconds then you know for sure that the service is being restarted by OS.如果您看到类似scheduling restart of crashed service in X seconds内容,那么您可以确定操作系统正在重启该服务。

If it is indeed the case, I doubt that you can kill it completely on a non-rooted device (neither I know how to achieve this on a rooted one).如果确实如此,我怀疑您能否在非 root 设备上完全杀死它(我也不知道如何在 root 设备上实现此目的)。

kill a process when you have the process name (basically you don't have to search 'ps' for the process ID and then kill it with PID):当你有进程名称时终止进程(基本上你不必搜索进程 ID 的“ps”然后用 PID 终止它):

adb shell kill $(pidof com.android.phone) adb shell kill $(pidof com.android.phone)

Use the following command from terminal: adb shell am crash [applicationId]从终端使用以下命令: adb shell am crash [applicationId]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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