<! -- @ Page {margin: 2 cm} P {margin-bottom: 0.21} -->
In the init. rc file, you can see the following services loaded:
Service zygote/system/bin/app_process-Xzygote/system/bin -- zygote -- start-system-server
Socket zygote stream 666
Onrestart write/sys/android_power/request_state wake
Onrestart write/sys/power/state on
Onrestart restart media
The code of the zygote service is in the directory:
Android-2.0/frameworks/base/cmds/app_process
The zygote service is mainly used to create a service listening user's command and create an application program to run according to the user's command.
Its main entry function code is as follows:
Int main (int argc, const char * const argv [])
{
// These are global variables in ProcessState. cpp
MArgC = argc;
MArgV = argv;
MArgLen = 0;
For (int I = 0; I <argc; I ++ ){
MArgLen + = strlen (argv [I]) + 1;
}
MArgLen --;
AppRuntime runtime;
Create a JAVA Runtime Library object.
Const char * arg;
Const char * argv0;
Argv0 = argv [0];
// Process command line arguments
// Ignore argv [0]
Argc --;
Argv ++;
// Everything up to -- or first non-arg goes to the vm
Int I = runtime. addVmArguments (argc, argv );
Add command line parameters here.
// Next arg is parent directory
If (I <argc ){
Runtime. mParentDir = argv [I ++];
}
// Next arg is startup classname or "-- zygote"
If (I <argc ){
Arg = argv [I ++];
If (0 = strcmp ("-- zygote", arg )){
Bool startSystemServer = (I <argc )?
Strcmp (argv [I], "-- start-system-server") = 0: false;
SetArgv0 (argv0, "zygote ");
Set_process_name ("zygote ");
Runtime. start ("com. android. internal. OS. ZygoteInit ",
StartSystemServer );
Create a java vm Based on the command line parameters. Run the VM from com. android. internal. OS. ZygoteInit and start all JAVA services.
} Else {
Set_process_name (argv0 );
Runtime. mClassName = arg;
// Remainder of args get passed to startup class main ()
Runtime. mArgC = argc-I;
Runtime. mArgV = argv + I;
LOGV ("App process is starting with pid = % d, class = % s .",
Getpid (), runtime. getClassName ());
Runtime. start ();
}
} Else {
LOG_ALWAYS_FATAL ("app_process: no class name or -- zygote supplied .");
Fprintf (stderr, "Error: no class name or -- zygote supplied .");
App_usage ();
Return 10;
}
}