标签:connect boolean manage 数值 select roc thread mon android
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha
+------------+ +-------+ +-----------+
|Linux Kernel+--> |init.rc+-> |app_process|
+------------+ +-------+ +-----------+
create and public
server socket
linux内核加载完成后,运行init.rc脚本
service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server socket zygote stream 666
create rumtime
+-----------+ +----------+
|app_process+----------> |ZygoteInit|
+-----------+ +-----+----+
|
|
| registerZygoteSocket()
|
+------+ startSystemServer() |
|System| <-------+ |
+------+ fork | runSelectLoopMode()
|
v
app_process进程
/system/bin/app_process 启动时创建了一个AppRuntime对象。通过AppRuntime对象的start方法,通过JNI调用创建了一个虚拟机实例,然后运行com.android.internal.os.ZygoteInit类的静态main方法,传递true(boolean startSystemServer)参数。
ZygoteInit类
ZygoteInit类的main方法运行时,会通过registerZygoteSocket方法创建一个供ActivityManagerService使用的server socket。然后通过调用startSystemServer方法来启动System进程。最后通过runSelectLoopMode来等待AMS的新建进程请求。
+
|
|
v fork()
+--------------+
|System Process|
+------+-------+
|
| RuntimeInit.zygoteInit() commonInit, zygoteInitNative
| init1() SurfaceFlinger, SensorServic...
|
|
| init2() +------------+
+-------> |ServerThread|
| +----+-------+
| |
| | AMS, PMS, WMS...
| |
| |
| |
v v
System进程是在ZygoteInit的handleSystemServerProcess中开始启动的。
##Android进程启动
+----------------------+ +-------+ +----------+ +----------------+ +-----------+
|ActivityManagerService| |Process| |ZygoteInit| |ZygoteConnection| |RuntimeInit|
+--------------+-------+ +---+---+ +-----+----+ +-----------+----+ +------+----+
| | | | |
| | | | |
startProcessLocked() | | | |
+---------------> | | | | |
| start() | | | |
| "android.app.ActivityThread" | | |
+-----------------> | | | |
| | | | |
| | | | |
| |openZygoteSocketIfNeeded() | |
| +------+ | | |
| | | | | |
| | <----+ | | |
| | | | |
| |sZygoteWriter.write(arg) | |
| +------+ | | |
| | | | | |
| | | | | |
| | <----+ | | |
| | | | |
| +--------------> | | |
| | | | |
| | |runSelectLoopMode() | |
| | +-----------------+ | |
| | | | | |
| | | <---------------+ | |
| | | acceptCommandPeer() |
| | | | |
| | | | |
| | | runOnce() | |
| | +------------------> | |
| | | |forkAndSpecialize()
| | | +-------------+ |
| | | | | |
| | | | <-----------+ |
| | | | handleChildProc()
| | | | |
| | | | |
| | | | |
| | | | zygoteInit() |
| | | +-------------> |
| | | | |
| | | | |in^okeStaticMain()
| | | | +---------------->
| | | | |("android.app.ActivityThread")
| | | | |
| | | | |
+ + + + +
标签:connect boolean manage 数值 select roc thread mon android
原文地址:http://www.cnblogs.com/yue31313/p/7400877.html