DeveloperLove
DeveloperLove

Reputation: 567

How to start a process on Android device using adb

I am using adb commands to manage processes on android phone.

I am able to kill a specific process by the command

adb kill "PID"  (PID is the process ID)

and the process gets killed.

But when I start it using the command

adb start "PID"

It doesnt start the process.

And the process that I wish to start is in /system/bin folder and I dont know what the package or activity name is of that process. All I know is "PID" and "User" of the process.

Is there any command that starts a specific process on android device?

Upvotes: 0

Views: 8085

Answers (3)

rav_kr
rav_kr

Reputation: 444

You said that you knew your binary is in /system/bin so I assume that you also know name of that binary file. In case you don't, that command will help you find out:

ps PID

To start a binaries (eg. uptime) you just have to type its name in shell:

adb shell
uptime

or in one command

adb shell uptime

but if your binary file isn't in one of the directories listed in $PATH you have to type whole path to it

adb shell /system/bin/uptime

you can check $PATH with:

adb shell echo $PATH

Upvotes: 0

Alex P.
Alex P.

Reputation: 31716

Native apps do not have activities. They are just that - native binaries.

If all you know is process' numeric ID - then ps <PID> command will show you the process binary's name in the NAME column. Like this:

# ps 407
USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME
root      407   1     4540   272   ffffffff 000160a4 S /sbin/adbd

If PPID value is 1 - it means that it has been started by system init and more likely than not the app is a "service" app. To control it you need to find the service's name and then just use stop <service> and start <service>.

To find the service's name run grep ^service /init*rc | grep <binary name> the service's name will be in the second column (i.e. "adbd"):

# grep ^service /init*rc | grep /sbin/adbd
/init.rc:service adbd /sbin/adbd

So to properly control this app - you should use stop adbd and start adbd.

Upvotes: 1

Rahul
Rahul

Reputation: 45090

Once you've killed the process corresponding to PID, how can you start it again?

You can instead try to launch an app from adb this way:-

adb shell
am start -n com.package.name/com.package.name.ActivityName

Or you can use this directly:

adb shell am start -n com.package.name/com.package.name.ActivityName

Upvotes: 3

Related Questions