Why the "adb shell monkey --wait-dbg" doesn't work? - android

I want to stop the running monkey by using the adb shell monkey --wait-dbg,but the result is only display like this:Sending WAIT chunkand then the monkey is still running.
How to understand the command?The official explain is "Stops the Monkey from executing until a debugger is attached to it."

I'm not sure as to why your command did not work, but you reported this as working:
adb shell ps | awk '/com\.android\.commands\.monkey/ { system("adb shell kill " $2) }'
This is a linux command line.
Let me explains it: it displays all running processes (ps), filter it to get the process id of "com.android.commands.monkey" (awk) then sends it a SIGTERM signal (kill).
ps(1) lists running processus.
kill(1) sends a SIGTERM signal from the linux kernel directly to the process you targeted.

Related

Kill processes from shell in Android

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]

ADB process blocks when starting background process

I am trying to run a shell script in the background on an Android phone via ADB. To simplify let's make it sleep 100:
$ adb shell
$ echo "nohup sleep 100&" > /data/local/tmp/test.sh
$ sh /data/local/tmp/test.sh
(does not block and returns to the shell immediately as expected. However:)
$ exit
(blocks until the sleep process is done)
Doing the same thing through a single adb command line is blocking as well:
$ adb shell sh /data/local/tmp/test.sh
Does run the script correctly, but the adb call blocks until 'sleep 100' is done. The sleep process keeps running if I CTRL-C out of adb, so the nohup part seems to be working correctly.
How can I get adb to exit after spawning the subprocess without forcefully killing the adb process on the host side?
adb shell 'nohup sleep 10 2>/dev/null 1>/dev/null &' works as expected - starts the process and does not block.

How to kill a process started by android am

I use the following command to start playing a movie on my android device:
adb shell am start -d file:///sdcard/fff.wvm -t video/3gp -a android.intent.action.VIEW
I want to stop (kill) the process before it finishes. Does anyone know the process name "am start" command create? I used ps to get the running processes in the background, but there is a lot, and it is hard to tell which one is.
If you know the package being started, use:
adb shell am force-stop <PACKAGE>
For me com.android.gallery worked pretty fine, however this depends on the installed app and preferred apps, of course. Going i.e. pushing Back might end the playback - it least it worked with the system player:
adb shell input keyevent 4
Appending the command ...
adb shell am kill-all
... should kill the process afterwards.

Killing android monkey process via adb only [duplicate]

This question already has answers here:
How do I stop the monkey madness?
(6 answers)
Closed 5 years ago.
I have a problem with a monkey process. Starting Monkey is easy, but how to stop it?
I know how to stop any process, but I have no idea how the monkey process is called.
DDMS shows a "?" process, and that's it, but I have to kill it with an adb command.
Any idea?
Command :
adb shell ps | awk '/com\.android\.commands\.monkey/ { system("adb shell kill " $2) }'
worked on android 2.3
Do adb shell ps
Search for process name monkey. note down pid of the monkey process
(pidvalue)
adb shell kill pidvalue. - where pidvalue is pid of monkey
process.
That's all. monkey runner is stopped.
Just run it with a set number of events:
$ adb shell monkey -p your.package.name -v NUMEVENTS
If you didn't know what you were getting into and ran monkey with a silly number of events (anything with > 3 zeros), you can kill it as described by both the answers in how do I stop the monkey madness!
On an emulator with Android 2.2 the monkey process is called 'app_process'.
You can stop it with
adb shell ps | awk '/app\_process/ { system("adb shell kill -9 " $2) }'

How do I stop the monkey madness?

I'm using the monkey tool to run a test of my Android application. For example, I might do a run like the following:
adb shell monkey -p com.myapp -v 10000
However, if I change my mind and need to cancel the test, there doesn't seem to be a way to do so that doesn't involve waiting multiple minutes for the damned monkey to finish most or all of its run.
Killing the adb shell process on my mac doesn't solve the problem. Killing the com.myapp process on my phone using ddms doesn't work. Unplugging my phone doesn't work.
How do I cancel the monkey madness?
You can kill the monkey process just doing this:
$ adb shell ps | awk '/com\.android\.commands\.monkey/ { system("adb shell kill " $2) }'
[Nitpick] You're confusing monkeyrunner with monkey.
The monkeyrunner tool is not related to the UI/Application Exerciser
Monkey, also known as the monkey tool. The monkey tool runs in an adb
shell directly on the device or emulator and generates pseudo-random
streams of user and system events. In comparison, the monkeyrunner
tool controls devices and emulators from a workstation by sending
specific commands and events from an API.
[/Nitpick]
On my Android 2.2 device when I start monkey, I see a process started in DDMS by the name "?" (just a question mark). When I killed that process, the monkey madness stopped.
adb shell
ps | grep monkey
kill process_id
adb shell kill $(adb shell pgrep monkey)
kudo to #deadfish
For what it's worth, I use Android Studio 3.1.4 on a Mac in 2018 and I had to alter the accepted answer like so:
./adb shell ps | awk '/com\.android\.commands\.monkey/ { system("./adb shell kill " $2) }'
Hope that help prevent some hair-pulling and pencil snapping out there!
Also... when it comes to the monkey, always be sure to pin your app!!! Otherwise you might accidentally send all your selfies to a random email in China like I did. ¯\_(ツ)_/¯
Kill the monkey by shell will cause a small problem, the IActivityController in ActivityTaskManagerService will not be set to null, which it should. And the ActivityManager.isUserAMonkey() still return true.
If monkey stop automatically, it will reset the Controller properly:
Monkey.java{
private int run(String[] args) {
...
try {
mAm.setActivityController(null, true);
mNetworkMonitor.unregister(mAm);
}
...
}
}

Categories

Resources