app_process command in Android

What is this app_process

Although not that popular “app_process” command is used heavily in Android, for example the well know “am” script is using it. Everybody knows how to start an application from adb shell:

am start -n yourpackagename/.activityname

However “am” is just a shell script and what stays in the base of the am script is our app_process binary:

root@android:/ # cat /system/bin/am
cat /system/bin/am
# Script to start "am" on the device, which has a very rudimentary
# shell.
#
base=/system
export CLASSPATH=$base/framework/am.jar
exec app_process $base/bin com.android.commands.am.Am "$@"

root@android:/ #

So app_process is the binary used to start java code. All the apps, instrumentations or installations are tarted using this.

Usage … NOT:

Lets see the official usage output:

root@android:/ # app_process
Usage: app_process [java-options] cmd-dir start-class-name [options]

Not quite complete as usual 🙂

Usage (full):

app_process [vm-options] cmd-dir [options] start-class-name [main-options]

Where:

  • vm-options – the VM options passed.
  • cmd-dir – the parent dir (/system/bin)
  • options – the arguments for this binary :

–zygote
–start-system-server
–application (api>=14)
–nice-name=nice_proc_name (api>=14)

  • start-class-name – the start-up class that contains main()  (com.android.commands.am.Am)
  • main-options – the arguments that are passed to the main() of the start-up class

Note for options:

  1. –start-system-server works only if –zygote
  2. if –zygote, start-class-name = com.android.internal.os.ZygoteInit
  3. and nice-name=zygote
  4. cmd-dir for api>=14 can be after options but always before start-class-name

Source code:

api < 14 : https://android.googlesource.com/platform/frameworks/base/+/54b6cfa9a9e5b861a9930af873580d6dc20f773c/cmds/app_process/app_main.cpp

api >= 14 : https://android.googlesource.com/platform/frameworks/base/+/ebed7d6e35f7f960e6e6add2b8ab7c7a31a511c3/cmds/app_process/app_main.cpp