Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release
thay vì aosp-main
để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Giới thiệu về các quy trình Zygote
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Zygote là một quy trình trong hệ điều hành Android đóng vai trò là gốc của tất cả các quy trình hệ thống và ứng dụng có cùng giao diện nhị phân của ứng dụng (ABI).
Trên các thiết bị hiện đại, chẳng hạn như Pixel 7 trở lên, có một quy trình Zygote 64 bit.
Ngoài ra, còn có WebView Zygote cho ABI chính, đây là một Zygote chuyên biệt chứa các thư viện và tài nguyên dành riêng cho các quy trình chạy WebView.
Sau đây là các tác vụ mà Zygote thực hiện:
Trình nền init tạo ra quy trình Zygote khi hệ điều hành Android được khởi chạy. Trên một số hệ thống kiến trúc kép, hai quy trình Zygote (64 bit và 32 bit) được tạo. Trang này chỉ đề cập đến các hệ thống kiến trúc đơn.
Zygote có thể tạo ngay các quy trình được gọi là quy trình ứng dụng không chuyên biệt (USAP) hoặc chờ tạo các quy trình khi ứng dụng cần.
Bạn phải bật tuỳ chọn trước đó thông qua một thuộc tính hệ thống hoặc lệnh cầu gỡ lỗi Android. Để biết thêm thông tin về cách định cấu hình Zygote để tạo các quy trình ngay lập tức, hãy xem phần Bật nhóm quy trình ứng dụng không chuyên biệt .
Bật nhóm USAP
Để cho phép sử dụng nhóm USAP, hãy làm theo một trong những cách sau:
Khi tính năng này được bật, mỗi Zygote sẽ duy trì một nhóm các quy trình phân nhánh thực hiện các phần độc lập với ứng dụng của quy trình khởi động ứng dụng.
Khắc phục sự cố về Zygote
Phần này chứa các giải pháp cho các vấn đề liên quan đến Zygote.
Zygote gặp sự cố
Nếu thiết bị của bạn không khởi động lại đúng cách và nhật ký hoặc báo cáo sự cố cho thấy các vấn đề với Zygote, thì có thể là do bạn đã thực hiện một thay đổi gần đây khiến initd hoặc máy chủ hệ thống gặp sự cố. Việc sửa mã sẽ khắc phục được vấn đề.
Lỗi từ chối SELinux hoặc lỗi IO
Zygote đặc biệt chú trọng đến việc vệ sinh chỉ số mô tả tệp trên các ranh giới quy trình. Khi chỉ số mô tả tệp xuất hiện tại thời điểm phân nhánh nhưng không có trong danh sách cho phép, chúng ta sử dụng lệnh gọi hệ thống dup
đến /dev/null
để ngăn việc vô tình sử dụng chỉ số mô tả tệp được lưu vào bộ nhớ đệm để truy cập vào các tệp mới mở.
Nếu bạn đang thực hiện các thay đổi về khung bao gồm việc cố gắng tải tài nguyên vào Zygote và bạn nhận được lỗi từ chối SELinux hoặc lỗi IO:
Đối với chỉ số mô tả tệp chưa đặt tên, hãy đưa chỉ số mô tả tệp vào vectơ fds_to_ignore
khi gọi Restat
.
Đối với chỉ số mô tả tệp được đặt tên:
- Chỉnh sửa
WORKING_DIRECTORY/frameworks/base/core/jni/fd_utils.cpp
.
- Thêm đường dẫn vào danh sách cho phép cho các tệp đang mở.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],null,["# About the Zygote processes\n\nThe *Zygote* is a process in the Android operating system that acts as the root\nof all system and app processes with the same application binary\ninterface (ABI).\n\nOn modern devices, such as Pixel 7 and later, there is a 64-bit Zygote process.\nIn addition, there is the *WebView Zygote* for the primary ABI, which is a\nspecialized Zygote\nthat contains libraries and resources specific to processes that run WebViews.\n\nHere are the tasks the Zygote performs:\n\n1. The init daemon spawns the Zygote process when the Android OS is\n initialized. On some dual architecture systems, two Zygote processes (a 64-bit\n and 32-bit) are spawned. This page covers only single architecture systems.\n\n2. The Zygote can immediately spawn processes called *unspecialized app\n processes (USAP)* or wait to spawn processes as needed by applications.\n The former option must be enabled through a system property or Android\n debug bridge command. For more information on configuring the Zygote to spawn\n processes immediately, see\n [Enable unspecialized app processes pool](#enable).\n\n - If the USAP pool is enabled on your device:\n\n 1. The system server uses a Unix domain socket to connect to an available USAP from a pool. The system server requests that the USAP is preconfigured for application use by changing the process's ID (PID), cgroup, and other information.\n 2. When the USAP is done preconfiguring, it replies to the system server with the PID.\n 3. When an application occupies one of these USAPs, the USAP is no longer part of the pool. When the pool reaches one or fewer USAPs in the pool, the Zygote replenishes the pool with new USAPs.\n - If your Zygote spawns processes using\n [lazy evaluation](https://en.wikipedia.org/wiki/Lazy_evaluation):\n\n 1. The system server receives a command that an app needs a process.\n 2. The system server uses a Unix domain socket to send a command to the appropriate Zygote.\n 3. The Zygote forks the process and changes the PID, cgroup, and other information.\n 4. When the process is complete, it sends the PID back to the Zygote which then passes it back to the system server.\n\nEnable USAP pool\n----------------\n\nTo enable the use of USAP pool, do one of the following:\n\n- Set the `dalvik.vm.usap_pool_enabled` system property to `true` in `/build/make/target/product/runtime_libart.mk`.\n\n- Run the following command:\n\n adb shell am broadcast -a \\\"com.google.android.gms.phenotype.FLAG_OVERRIDE\\\" --es package \\\"com.google.android.platform.runtime_native\\\" --es user \\\"\\*\\\" --esa flags \\\"usap_pool_enabled\\\" --esa values \\\"true\\\" --esa types \\\"string\\\" com.google.android.gms\n\nWhen this feature is enabled, each Zygote maintains a pool of forked processes\nthat perform the application-independent portions of the application startup\nprocess.\n\nTroubleshoot Zygote issues\n--------------------------\n\nThis section contains solutions to Zygote-related issues.\n\n### The Zygote is crashing\n\nIf your device doesn't reboot properly and your logs or crash reports show\nissues with the Zygote, it's likely because you made a recent change that\ncauses initd or the system server to crash. Fixing your code should fix\nthe problem.\n\n### SELinux denials or IO Failures\n\nThe Zygote is particular about file descriptor hygiene across process\nboundaries. When file descriptors are present at fork time but not in an\nallowlist, we use a `dup` system call to `/dev/null` to prevent cached file\ndescriptors from being used unintentionally to access newly opened files.\n\nIf you're making framework changes that include trying to load\nresources into the Zygote, and you're receiving SELinux denials or IO failures:\n\n- For unnamed file descriptors, include the file descriptors in the `fds_to_ignore` vector when `Restat` is called.\n\n- For named file descriptors:\n\n 1. Edit \u003cvar translate=\"no\"\u003eWORKING_DIRECTORY\u003c/var\u003e`/frameworks/base/core/jni/fd_utils.cpp`.\n 2. Add the path to the allowlist for open files."]]