+------------+ +-------+ +-----------+ |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") | | | | | | | | | | + + + + +
如对本文有疑问, 点击进行留言回复!!
android -- ndk (stack corruption detected)
Android Span富文本图文混排 - ImageSpan(图文垂直居中)
Element DateTimePicker日期时间选择器的使用示例
【Appium踩坑】小米手机,启动报错:exited with code 255 writing to settings requires:android.permission.WRITE_SECUR
android 拍照 预览图与 照片分辨率(可视区域)不一致
[PAT顶级]1025 Keep at Most 100 Characters (35分)
网友评论