I was trying to kill my camera process in adb (i'm running android R) using this command:
kill -HUP ps -A | grep camera | awk '{print $2}'
but after i hit enter, it gave me an error:
/system/bin/sh: kill: ps: arguments must be jobs or process IDs
/system/bin/sh: kill: -A: arguments must be jobs or process IDs
Any idea on how to fix this?
Suggest to use command pkill and learn about pgrep as well.
pkill -9 -f "camera"
Related
I try to find some way to kill unnecessary services/processes in Android from shell.
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:
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.
Is it something that can only be done in init.rc ?
Thanks,
This service is probably started as STICKY - it will be automatically restarted by OS after some predefined timeout.
You can check it by pulling the logcat from the device and grepping it for the name of the service you attempted to kill:
$ 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.
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).
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):
adb shell kill $(pidof com.android.phone)
Use the following command from terminal:
adb shell am crash [applicationId]
Is it possible to kill ALL the active tasks/apps in the task manager using ADB? This would be equivalent of opening the task manager and killing each task one by one...
I tried using the the following adb shell command but that didn't kill all the task.
adb shell am kill-all
I can't use the adb shell am force-stop <PACKAGE> command because it would require me to know which package/app is running. I want to kill ALL the user apps task that are running. Similarly to using the task manager and killing each task one by one.
According to the command description, kill-all kills all background processes. Are background processes equivalent to "services" and task equivalent to "activities"?
Also, is it possible to clear cache of apps using ADB while keeping the user data? I seems that the adb shell pm clear clears all the user data. I want to only clear the cache.
The reason why I am asking is because I am doing some performance testing on few user apps. To make each test valid, I want to ensure none of the user apps have any task, activities, services, and cache already in the background.
You can use force-stop, it doesn't require root permission.
adb shell am force-stop <PACKAGE>
And you can get the package name from the top running activity/app
adb shell "dumpsys activity | grep top-activity"
After that you need to play a bit with the result, to extract the package, here my java code that does that:
public void parseResult(String line){
int i = line.indexOf(" 0 ");
if(i == -1){
return;
}
line = line.substring(i);
i = line.indexOf(":");
if(i == -1){
return;
}
line = line.substring(i + 1);
i = line.indexOf("/");
return line.substring(0, i);
}
If you want to start clean slate i.e close the app and clear its data too you can do the following
adb shell pm clear com.yourapp.package
For non rooted devices I expanded on Faisal Ameer's Script
adb shell ps | grep -v root | grep -v system | grep -v "android.process." | grep -v radio | grep -v "com.google.process." | grep -v "com.lge." | grep -v shell | grep -v NAME | awk '{print $NF}' | tr '\r' ' ' | xargs adb shell am force-stop
The adb shell am force-stop does not require root permission. Note that the applications still show up in the devices running application drawer but I have verified that the packages processes have been cleared using.
adb shell dumpsys meminfo relevant.package.names
find running apps, ignoring system apps etc and kill, the following command does it all;
adb shell ps|grep -v root|grep -v system|grep -v NAME|grep -v shell|grep -v smartcard|grep -v androidshmservice|grep -v bluetooth|grep -v radio|grep -v nfc|grep -v "com.android."|grep -v "android.process."|grep -v "com.google.android."|grep -v "com.sec.android."|grep -v "com.google.process."|grep -v "com.samsung.android."|grep -v "com.smlds" |awk '{print $2}'| xargs adb shell kill
you can add more exceptions if you find any like this; grep -v "exception"
I really need help here...
I am writing a shell script, which starts a process then kills it every 10 seconds then restarts it again.
I understand that using 'ps' command will show all the processes that are running and you can kill it by running 'kill [pid]'.
However, grepping the PID of the process that I am launching is not easy.
I've looked everywhere and for some reason, I cannot use functions like pgrep, awk, xargs, pidof... They are just not found...
I can only think of a way where I have to output the ps file then parse it and grab the PID alone.. but that seems too much...
Can anyone help me? I think I am only limited to using ps and grep only...
I am launching the phone application by running
am start -a android.intent.action.CALL -d tel:XXX-XXX-XXXX
Then by running 'ps m.android.phone' I can use kill [PID] to stop call the call
I've also tried running commands like
pm clear com.android.phone,
adb shell am force-stop com.android.phone
but none of them would stop the call...
Please help
Thanks a lot!
Use
am kill package-name
or
am force-stop package-name
replacing package-name by the name of the application you want to kill.
If you know the process name of the application, then I wrapped together a very quick and dirty script to parse the PID of the process:
ps -u $(whoami) | grep firefox | awk '{printf $1}'
You should obviously replace firefox with your process name of choice.
Please note that I am no expert on the area, but it works on my end.
You could try the command pidof to get the process id directly, eks:
pidof apashe2
following what marcus said:
adb shell kill -9 $(adb shell ps | grep firefox | awk '{print $1}')
I am able to start native applications using am start -a action -n packagename/activity. How can I kill/stop a native application from adb shell?
adb shell am force-stop packagename
Chirag deleted it, so here it is again:
adb shell ps | grep com.myapp | awk '{print $2}' | xargs adb shell kill
This is to be run outside of the emulator. It is one long Unix command, not four commands with a visual separation. | is syntax, interpreted by your (Ubuntu's) shell, which then pipes the output from adb, grep, etc., into the next. Only ps is executed in the emulator.
Another way to kill your app is to send your app to backround (using home button) and call:
adb shell am kill com.your.package
It works not on all of my devices, however, on devices where it works it behaves the same way as if the app was killed in background due to lack of resources and this state is often handy to test different aspects of your process recreation.
For example, if you have Broadcast Receivers registered in Manifest, they will still start without restarting your app manually, comparing to force stop that you can achieve using:
adb shell am force-stop com.your.package
Please try the below command in adb shell.
adb shell kill <PID>
i have many application running on my emulator but ps -ef does not show any process y?
It seems like Android's ps does not accept the argument -ef. Try issuing ps only?
adb shell ps | grep com.android.mms | awk '{print $2}'
This gives the process id of the attached process