Android adb shell ,ps-ef does not show any process? - android

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

Related

Error killing Camera process in ADB, Android R

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"

Get IMEI via ADB only for old Huawei models

I need a bit of assistance. I have a Huawei g6-l11 (with Android 4.3) from which I am trying to extract the IMEI via ADB. I know that this device is ancient, but this is one of my tasks. So far I had tried everything I could find on the internet, like:
1) adb shell getprop | grep "<IMEI>"
2) adb shell service call iphonesubinfo N | grep "<IMEI>" - Where N is a number between 1 and 50
3) adb shell settings get secure android_id
4) adb shell content query --uri content://settings/secure | grep "<IMEI>"
5) adb shell content query --uri content://settings/system | grep "<IMEI>"
6) adb shell content query --uri content://settings/global | grep "<IMEI>"
7) adb shell dumpsys | grep "<IMEI>"
So I had made an Android app and run this piece of code on the smartphone:
val tm = this.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
Log.d("Emy_","The IMEI is ${tm.deviceId}")
That worked fine but it is an Android app when I need to do the same thing but only via ADB.
Also, I had found a fastboot command that would help me (like: fastboot oem get-psid). But the problem is that I need to reboot the phone into fast boot mode. Which is taking too long.
My questions are:
1) why is it different for Huawei models with the OS version below Marshmallow to extract the IMEI?
2) how could I replicate the function call done by the Java code to be done with the ADB in the terminal? Or in other words, what other commands would you recommend to me to try to extract the IMEI?
You could display it on screen:
adb am start -a android.intent.action.CALL -d tel:*%2306%23
If you just searching to know the IMEI, You can try this code : *#06#
Or you can try this : adb shell
service call iphonesubinfo 1 | toybox cut -d "'" -f2 | toybox grep -Eo '[0-9]' | toybox xargs | toybox sed 's/\ //g'
hop that help you !

[Android]How to pass a process number to cmd line "adb shell kill "

I would like to find a specific target's pid and kill this process.
Then, i made a shell:
#!/bin/bash
#
func(){
while true; do
adb shell ps | grep my-target-process | awk '{print $2}' | xargs adb shell kill
sleep 1
done
}
But, i always get errors like below :
usage: kill [-s signame | -signum | -signame] { job | pid | pgrp } ...
kill -l [exit_status ...]
Is there anything wrong? Thanks.
I will add an explanation the logic I suggested in the comments section. The reason why
| xargs -I{} adb shell kill "{}"
works is, with the -I{} flag in xargs, the {} becomes a placeholder for the output returned from the previous command, i.e. the process-id is now present in {} and can be passed as an argument/input to your kill command.
(also) As an alternative, if your Android version supports pidof command, which returns the process-id pid directly, you can do
adb shell pidof -s "my-target-process" | xargs -I{} kill "{}"

adb: Find PID from the adb shell

I am trying to get the PID of the process INSIDE adb shell. So, I am doing adb shell which gets me to the android shell. Now, if I were to get the PID using a regular shell I would use
adb shell ps | grep android.process.acore | sed 's/\s\s*/ /g' | cut -d ' ' -f 2
OR
adb shell ps | grep android.process.acore | awk '{ print $2 }'
I get the PID (a numeric number - 2nd field of the ps | grep android.process.acore) output.
However, if I run the above commands inside android shell(after doing adb shell), I get /system/bin/sh: sed: not found and /system/bin/sh: awk: not found errors respectively. Which means, these commands are not available inside adb shell. However, grep works.
The output of the ps | grep android.process.acore inside adb shell is:
XXX_x21 11826 441 502296 39028 ffffffff 4010ff6c S android.process.acore
I am looking for the number 11826.
How can I extract it inside adb shell?
Also, please help if there is a direct way to get the PID inside the adb shell.
Regards,
Rumit
Android versions starting with 6.0 already include pidof utility:
usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME]...
Print the PIDs of all processes with the given names.
-s single shot, only return one pid.
-o omit PID(s)
Not sure if you can get the PID directly however you can try the following
set `ps |grep android.process.acore`
echo $2
This has the affect of setting the output of the ps command into variables $1, $2, $3 etc. The PID value is in $2
I tried this one and it seems to work:
adb shell "set "ps | grep android.process.media"; kill -9 $2"
adb shell pidof [package name]
or
adb shell pidof -s [package name]
-s option is for single shot, returning only one pid.
I tried this one and it seems to work:
adb shell
ps -A | grep "android.process.acore"

Android - Force Stop Google Framework

I am having some problems on my C2DM connection, and to fix it I need to Force Stop "Google Services Framework".
I would like to automate it, so I have two questions.
1 - Is possible to write some Java code or terminal commands to my application reproduce:
Settings > Apps > All > Google Services Framework > Force Stop ?
(I have SU)
Just kill the process will do exactly that?
2 - What is the package name of Google Services Framework?
com.google...?
GSF package is com.google.android.gsf
On adb:
This does the trick
adb shell ps | grep com.google.android.gsf | awk '{print $2}' | xargs adb shell kill
In Java:
I'm going out on a limb with the kill command, but shell command running code is perfecto.
String killer = "ps | grep com.google.android.gsf | awk '{print $2}' | xargs kill"
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes(killer+"\n");
os.writeBytes("exit\n");
os.flush();
Have fun killing GSF!

Categories

Resources