when you run a binary in adb shell, if you exit adb, then the process is over too.
So is there a way to run a binary without adb's help?
If you have busybox installed on your device, then you could use 'busybox nohup [your binary] &' command. This way it will keep running even after you close adb
This works for me:
sh -c "your-binary-or-command" &
Then you can exit the adb shell by pressing ctrl+D and it will continue to run.
You can kill it by going back into the adb shell then
kill -s KILL <PID>
Related
I need to take the native dump of the android process.
The cmd I am using is:
adb shell am dumpheap -n <pid> /data/local/tmp/dump.txt
The device is S8, Oreo OS.
Everytime I run this cmd, the 'dump.txt' is generated with the following content:
Native heap dump not available. To enable, run these commands
(requires root):$ adb shell setprop libc.debug.malloc 1 $ adb shell
stop $ adb shell start
Though I am doing it says and the phone is also rooted but it still gives the same content.
I am stuck. Any help would be appreciated.
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.
I'm using an Android-x86 vm running in vmware fusion for some testing purposes. I am pushing files to it via adb push, however, every time I uninstall and reinstall the app, I have to execute the following:
adb shell
su
chmod 777 /my/path
exit
exit
I need to be able to script out this entire process but I'm not sure how I can manage the chmod process via some sort of script. I tried doing something like
adb shell am chmod 777 /my/path
But that doesn't work. I thought it would because I can do
adb shell am start ...
I also tried:
adb shell "su && chmod 777 /my/path && exit && exit"
which actually works, but doesn't exit the shell process. So any advice is much appreciated.
You can pass commands to adb shell, as you mentioned, though it works better if you surround the command in quotes.
Likewise, you can pass commands to the 'su' command using the -c argument. Add all of this together and it should do what you want in a nice one-liner!
adb shell "su -c 'chmod 777 /my/path'"
I have a simple problem.
I want to start/run a program file on an android phone using adb shell.
My Program is in /system/bin folder and has root privileges.
I want to run this program from my command prompt as adb shell runme 3000000 > logs.txt but it should not block the terminal, It should run in background.
I cannot use screen/disown/nohup for my problem as android doesn't have all this.
I tried
adb shell "runme >logs.txt &" but of no use.
When i issue command as
adb shell
# runme 3000000 > logs.txt &
It runs fine, when i exit the terminal/disconnect the device and then connect again to system.
Do adb shell ps | grep runme shows the process is still runnning in background.
Thanks
Busybox has nohup applet which works just fine in Android
I can use all adb features, but when i try to adb -r install /package.adb it just gives me:
"2858 KB/s (4116553 bytes in 1.406s)"
and thats it, nothing happens. When I do it on another computer it deploys application and restarts it. What can be wrong?
Try running this command after your install:
adb shell am start -a android.intent.action.MAIN -n your.package/.possibleSubfolder.MyMainActivity