【网学网提醒】:网学会员为您提供Android Initialization Process参考,解决您在Android Initialization Process学习中工作中的难题,参考学习。
AndroidInitializationProcess---Sinkin(jinzhcheng@tom)
init是内核启动后创建的第一个进程,由相关代码组成:system/core/init/builtins.csystem/core/init/init.csystem/core/init/devices.csystem/core/init/property_service.csystem/core/init/util.csystem/core/init/parser.csystem/core/init/logo.cItdoesthefollowingtasksstepbystep:(以下摘自Steve’sSpace)1.Initializelogsystem.2.Parse/init.rcand/init.%hardware%.rc.3.Executeearly-initactioninthetwofilesparsedinstep2.4.Devicespecificinitialize.Forexample,makealldevicenodein/devanddownloadfirmwares.5.Initializepropertysystem.Actuallythepropertysystemisworkingasasharememory.LogicallyitlookslikearegistryunderWindowssystem.6.Executeinitactioninthetwofilesparsedinstep2.7.Startpropertyservice.8.Executeearly-bootandbootactionsinthetwofilesparsedinstep2.9.Executepropertyactioninthetwofilesparsedinstep2.10.Enterintoanindefinitelooptowaitfordevice/propertyset/childprocessexitevents.Forexample,ifanSDcardisplugined,initwillreceiveadeviceaddevent,soitcanmakenodeforthedevice.Mostoftheimportantprocessisforkedininit,soifanyofthemcrashed,initwillreceiveaSIGCHLDthentranslateitintoachildprocessexitevent,sointheloopinitcanhandletheprocessexiteventandexecutethecommandsdefinedin*.rc(itwillruncommandonrestart).均通过Socket来完成监控。其中用于监控device的Socket是用来监控内核kobject子系统发送的NETLINK_KOBJECT_UEVENT事件The.rcfileisascriptfiledefinedbyAndroid.Thedefaultisdevice/system/rootdir/init.rc.Wecantakealootatthefileformat(device/system/init/readme.txtisagoodoverallintroductionofthescript).Basicallythescriptfilecontainsactionsandservices.Actions------Actionsarenamedsequencesofcommands.Actionshaveatriggerwhichisusedtodeterminewhentheactionshouldoccur.Whenaneventoccurswhichmatchesan
action'strigger,thatactionisaddedtothetailofato-be-executedqueue(unlessitisalreadyonthequeue).Eachactioninthequeueisdequeuedinsequenceandeachcommandinthatactionisexecutedinsequence.Inithandlesotheractivities(devicecreation/destruction,propertysetting,processrestarting)"between"theexecutionofthecommandsinactivities.Actionstaketheformof:on
...Services-------Servicesareprogramswhichinitlaunchesand(optionally)restartswhentheyexit.Servicestaketheformof:service[]*