Rasmus Nørgaard
Masters on Mobile
Published in
2 min readMar 5, 2015

--

The Zygote Process

The Zygote process appropriately gets is name after the dictionary definition of the word: “It is the initial cell formed when a new organism is produced”.

Zygote is a special process in Android which handles the forking of each new application process. These processes are simply regular Linux processes. We may think of the Zygote as the template process for each app and service that is started on the device. It is launched by the Android runtime, which also starts the first Virtual Machine (VM). The VM then calls Zygote’s main() method which causes Zygote to preload all shared Java classes and resource into memory. We may think of it as a warmed up process, ready to be deployed at a later point.

The Zygote process is quite central to the startup process. Also in part because it launches the System Server, which plays an essential role in Android. Image source: Embedded Android

Each new Zygote process is a child of the original Zygote process and includes a VM. Thus with each new request to launch an application a new process is forked and a new VM is created, and the application is then bound to the thread of this process. Thus each application runs in its very own Linux process, with its own thread. We may think of each process as a software component container.

These containers hold, once loaded, the activities, services and content provider components of the application, and may, due to pre-loading of shared libraries, launch within milliseconds. This makes them readily available when a new application is requested. The new application then receives a map, not a copy, of the classes. This dramatically reduces load time of applications, and is an optimization made to accommodate the limited resources available. Because each container recieves a map, these resources are shared between applications, eliminating the need for each new fork of the VM to keep its own copy of classes and resources. It is the Linux kernel ‘copy-on-write’ feature that enables this functionality.

Remember at this point the Zygote process still hasn’t received a call from the Activity Manager to launch an application, but the container is prepared, and once the call comes in, the specific Application Package (APK) will be loaded into the VM.

Finally the Zygote starts the System Server before settling into a listening mode, on its socket, for requests to eventually be sent to it from the Activity Manager.

--

--