"Go" Android process mechanism

Source: Internet
Author: User

The following extracts from the old Luo's Android tour blog, is the old Luo's blog on the android underlying principles of an abstract knowledge summary (if there is an erroneous welcome point) (Invasive deletion):
http://blog.csdn.net/luoshengyang/article/details/8923485
http://blog.csdn.net/luoshengyang/article/details/12957169

Organize by Doing

Android System Boot Overviewzygote process started by the Init processIn a Linux system, all processes are descendants of the Init process, meaning that all processes are directly or indirectly forked by the INIT process. The zygote process is also a system-initiated process created by the INIT process.
    1. The init process creates the zygote process when the system starts, and the zygote process is responsible for the creation and start-up of other processes in subsequent Android application framework layers.
    2. The zygote process first creates a systemserver process, and the systemserver process is responsible for initiating the critical services of the system. such as package management Service Packagemanagerservice and application component Management Service Activitymanagerservice.
    3. When we need to launch an Android application, Activitymanagerservice notifies the zygote process to create a new process for the application through the socket interprocess communication mechanism.
Address space after the zygote process starts:Android Application process startup process
    1. In an Android system, all application processes and system service processes are systemserver by the zygote process (fork).
    2. Two important services in the system Packagemanagerservice and Activitymanagerservice are initiated by the systemserver process, And the systemserver process itself is the zygote process in the process of starting fork out.
    3. When Activitymanagerservice launches an application, it communicates with the zygote process through the socket and requests it to fork a subprocess out as the process of the application that is about to start;
    4. Under what circumstances will the Activitymanagerservice component create a new process for the application? : When the system decides to start an activity or service in a new process, it creates a new process and then initiates the activity or service in the new process.
    5. Android Application Process startup process: Specifies that the entry function for the new process is the main function of Activitythread ; Provides an infrastructure for binder interprocess communication mechanisms for in-process binder objects (defines the binder thread pool: When we are developing Android applications, when we are communicating with other processes, we define our own binder objects, After the remote interface of this binder object is passed through other processes, other processes can invoke the function of our application process through the remote interface of this binder object)
Address space after the System server process starts:Android Application Process Recycling mechanismThe memory recovery mechanism of Linux--Out of Memory Killer
    1. Each process has a Oom_adj value, and the value range [ -17,15] can be accessed through/proc/<pid>/oom_adj
    2. The Oom_adj initial value of each process equals the OOM_ADJ value of its parent process
    3. The smaller the Oom_adj value, the less likely it is to be killed, where 17 means it will not be killed.
    4. When memory is tight, OOM killer The memory consumption, CPU time, survival time, and Oom_adj value of the synthetic process to determine whether to kill a process to reclaim memory
Android's memory recovery mechanism-Low Memory Killer
    1. The Oom_adj value of the process is calculated by activitymanagerservice based on the state of the component running inside the process
    2. Process Oom_adj value range is [ -16,15], the smaller the Oom_adj value, it is not easy to be killed
    3. When memory is tight, LMK determines whether to reclaim a process based on the OOM_ADJ value
    4. Activitymanagerservice and Windowmanagerservice Process recycling under certain circumstances
    5. LMK Process Recycling Policy: When system memory is less than I, in a process where the OOM_ADJ value is greater than or equal to J, select a process that has the highest Oom_adj value and consumes the most memory to reclaim
Oom_adj value of the application process:
    • System_adj ( -16): System server process
    • Persistent_proc_adj ( -12): Android:persistent property is true for systems app processes, such as Phoneapp
    • Foreground_app_adj (0): Process containing foreground activity
    • Visible_app_adj (1): Process containing visible activity
    • Perceptible_app_adj (2): a process that contains activity with a status of pausing, Paused, stopping, and a process that runs a foreground service
    • heavy_weight _app_adj (3): Heavyweight process, Process Android:cantsavestate property is true, not currently open
    • Backup_app_adj (4): process that is performing a backup operation
    • SERVICE _adj (5): Recently active service process
    • Home_app_adj (6): Homeapp process
    • Previous_app_adj (7): The process in which the previous APP was running
    • Service_b_adj (8): The most recently inactive SERVICE process
    • Hidden_app_min_adj (9) and Hidden_app_max_adj (15) when the number of SERVICE_ADJ processes reaches a certain value : A process with invisible activity, given a value in [9,15] according to the LRU principle
    • The Oom_adj value of the init process is set to 16, and the oom_ of the daemon and service processes initiated by the INIT process The Adj value is also equal to -16
    • if the content provider is running in process A or the service is bound to process B, and the Oom_adj value of process B is smaller than the oom_adj of process A, then the oom_ of process a The ADJ value is set to the Oom_adj value of process B, but cannot be less than Foreground_app_adj
Activitymanagerservice updates the Oom_adj value of the application process in the following four scenarios, and kills the application processes that are running on apps that have been uninstalled:
    • Activitystopped: Stop Activity
    • Setprocesslimit: Setting the number of processes limit
    • Unregisterreceiver: Logoff broadcast Receiver
    • Finishreceiver: End Broadcast Receiver
Windowmanagerservice when an out of memroy occurs during the processing of a window, the Activitymanagerservice is also notified to kill those application processes that contain Windows

"Go" Android process mechanism

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.