Android Training Course (35)

Source: Internet
Author: User

<! -- @ 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;

}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.