Android App startup process

Source: Internet
Author: User

The process of running the native process

General procedures for the start-up procedure, you can use the description. The program is parsed by the kernel, uses the shared library required by the linker link, and executes from the portal of the C Runtime library.

Typically, the native process is initiated by the shell or INIT, starting with the following process:

    • The shell receives the command to start a program, at which point the shell first fork a new process
    • The new fork process, through EXECVE system calls, falls into the kernel, and the kernel checks and loads the binary image files that need to be executed to verify their legitimacy and permissions. Usually the user-state process starts a new program (such as a shell), and after the fork, the Execve must follow, which will be more efficient (because of the use of cow technology, which avoids page table duplication, and after Execve, all the content in the previous process is useless, If the execve immediately after the fork, can avoid the cow caused by the copy);
    • Usually binary files will depend on some system dynamic library, at this time kernel will start loader/system/bin/linker, execute linker __linker_init ()
    • Linker's Linker_init (), parses the binary elf file, loads the dependent dynamic library file, and then goes into the binary image of the entry function __start execution
    • __start will call the C library's initialization function __libc_init ()
    • __libc_init () invokes the main function of the image, which is the entry function of the user app, which is the main function
    • When the main () function finishes executing, exit the process execution via exit ()

It is important to note that Android Bionic provides the loader is/system/bin/linker, while the common Linux system glibc is/lib/ld-linux-xx.so.2. This is one of the reasons why other Linux platforms are binary files with the instruction architecture and cannot be run on Android: the loader that started the user process is the first step in the process of making a mistake.

The process of running the Java process

Java process startup is very special, the Java process is zygote started, zygote after the folk process, and did not execute the execve instruction, so is shared zygote code snippets and data segments. Other Java processes can be thought of as zygote clones, cloned processes, and their respective roots to explain the Java language in their own needs (Java code).

That is to say: All Android processes, from the native perspective are zygote. The corresponding program is/system/bin/app_process, and the virtual machine is running in it.

So why is the Java process so different? In fact, from the native point of view, different Java programs, can be so understood: just/system/bin/app_process this program, because of different input (Java Dex bytecode) and caused by.

, the user apk is actually a clone of the city Zygote (the process of starting and entering main, etc. is not drawn, the app process does not have this step, it is cloned from the zygote process), The difference in the performance of the Java code that is primarily performed by the DVM virtual machine varies greatly from the behavior that results.

The Java process does not perform an exec call, which has a big benefit: Using Linux's Cow (copy on Write) technology, you can share memory resources-primarily Java's core libraries-across multiple Java processes.

Java programs can also use the native library, where the native library needs to be opened through the Dlopen (that is, Java, using the System.loadlibrary () method to load the so library, the virtual machine corresponding to the C library method called), Dlopen the process of loading so library , the elf information of the so library is still processed through linker analysis, and other dependent dynamic libraries are loaded.

(Note: zygote is actually/system/bin/app_process,zygote just app_process alias)

Http://www.cnblogs.com/lanrenxinxin/p/4943632.html

Android app startup process (GO)

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.