Android---zygote and system process startup process brief analysis

Source: Internet
Author: User

Android---zygote and system process startup process brief analysis

after reading the zygote launch section of the Android scenario source code, make a brief summary of the following. The zygote process is started as a service during the INIT process startup process:    service Zygote/system/bin/app_process-xzygote/system/bin--zygote--start-system-serverclass Mainsocket zygote Stream 660 root system   The first line indicates that the zygote process started as a service, its corresponding executable is/system/bin/app_process, and the next four parameters are its startup parameters. The second name indicates that in the zygote boot process, in order to create a socket named Zygote, its permissions under Linux is 666, that is, all users can read and write to it. because Zygote is started as a service, ANDROID-5.1.0_R3\ANDROID5.1\SYSTEM\CORE\INIT\INIT.C's Service_start () during Init startup function is called.     the main tasks of the Service_start function are:
    • Create a new child thread by using the fork () method, which is the zygote thread
    • Call the Create_socket () function to create a zygote socket in the startup script and save the file descriptor for the int type of the socket. When created, a socket address of type Af_unix is also created for this socket, and the bind () method is called to bind the socket to this address. The socket also has a corresponding device file,/dev/socket/zygote.
    • After the socket is created, the Publish_socket () function is called to publish the socket to the system. Using the environment variable, android_socket_zygote-the SOCKET file descriptor.
    • Call Execve (Svc->args[0]) to execute App_process's main program app_main.cpp. At this point, the code enters the native layer.
 The main functions of the app_main.cpp are:
    • By invoking the Appruntime::start () function, the Zygote:AppRuntime.start ("Com.android.internal.os.ZygoteInit", args) is further initiated by means of JNI; Args is the parameter list, which is more important to mark whether you want to start the system process, record the socket name.
 The main functions of the zygoteinit are:
    • Call the Registerzygotesocket ("zygote") function to obtain a description of the zygote socket file and create a local service socket:localserversocket based on this descriptor. This service socket is used to wait for the Activity Management Service Activitymanagerservice request the zygote process to create a new application process.
    • Call the Startsystemserver () function to start the system process so that it can start up critical services for the systems. This method creates the system process through the forksystemserver () function, and finally calls Handlesystemserverprocess () to further launch the system process (" Com.android.server.SystemServer ", through reflection technology),"--runtime-init "indicates the need to provide binder services.
    • Call Runselectloop () to wait for the Activity Management Service Activitymanagerservice request zygote process to create a new application process.
 The main functions of the systemserver are:
    • Start a thread to start the system's critical services.

Android---zygote and system process startup process brief analysis

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.