Dalvik和Zygote进程有什么关系?

What's the relationship between Dalvik and Zygote process?

我只想知道:

Dalvik VM 的作者是 Dan Bornstein
每个 android 应用程序都在一个单独的进程中运行,有自己的 Dalvik VM。

Zygote is a daemon with the only mission to launch applications. This means that Zygote is the parent of all App process. When app_process launches Zygote, it creates the first Dalvik VM and calls Zygote’s main () method. Once Zygote starts, it preloads all necessary Java classes and resources, starts System Server and opens a socket /dev/socket/zygote to listen for requests for starting applications.

加个例子说明Zygote是所有App进程的父进程。 zygote PID : 481, my application processes PPID : 481, you can use ps 命令检查。

UID            PID  PPID C STIME TTY          TIME CMD
root           481     1 0 09:17:54 ?     00:00:03 zygote
u0_a132      28993   481 78 09:07:53 ?    00:23:46 com.languouang.helloworld
u0_a132      29013   481 0 09:07:53 ?     00:00:01 com.languouang.helloworld:countservice
u0_a132      29296   481 1 09:09:04 ?     00:00:09 com.languouang.helloworld:mall
u0_a132      30427   481 1 09:16:42 ?     00:00:15 com.languouang.helloworld:faq

Zygote 实际上是启动进程启动时出现的 init 进程的子进程。 它负责加载执行 Dalvik 字节码的 Dalvik 虚拟机。此外,它将所有必要的资源全部共享 java 类 和资源预加载到内存中。