【android学习笔记】init.rc中声明的守护进程启动的流程

本文详细解析了Android系统中init.rc文件中声明的守护进程如何启动,包括service关键字、各种选项如class、disabled、user和group等的作用,并以surfaceflinger和bootanimation为例,探讨了启动流程和条件。当系统启动时,通过class_start命令启动对应类别的服务,而disabled的服务则需要特定条件才能启动。
摘要由CSDN通过智能技术生成

在Init.rc中,用service关键字声明了一系列服务.

init.rc对service的说明如下:(详见system/core/init/readme.txt)

Services--------Services are programs which init launches and (optionally) restartswhen they exit.  

Services take the form of:service <name> <pathname> [ <argument> ]*   <option>   <option>   ...

Options-------Options are modifiers to services.  

They affect how and when initruns the service.

critical   

This is a device-critical service. If it exits more than four times in   four minutes, the device will reboot into recovery mode.

disabled  

 This service will not automatically start with its class.   It must be explicitly started by name.

setenv <name> <value>   

Set the environment variable <name> to <value> in the launched process.

socket <name> <type> <perm> [ <user> [ <group> ] ]   

Create a unix domain socket named /dev/socket/<name> and pass   its fd to the launched process.  <type> must be "dgram", "stream" or "seqpacket".   

User and group default to 0.

user <username>   

Change to username before exec'ing this service.   Currently defaults to root.  (??? probably should default to nobody)   Currently, if your process requires linux capabilities then you cannot use   this command. You must instead request the capabilities in-process while   still root, and then drop to your desired uid.

group <groupname> [ <groupname> ]*   

Change to groupname before exec'ing this service.  Additional   groupnames beyond the (required) first one are used to set the   supplemental groups of the process (via setgroups()).   Currently defaults to root.  (??? probably should default to nobody)oneshot   Do not restart the service when it exits.

class <name>   

Specify a class name for the service.  All services in a   named class may be started or stopped together.  A service   is in the class "default" if one is not specified via the   class option.

onrestart    Execute a Command (see below) when service restarts.

可以看出,service中比较关键的几个选项是类别(class),启动选项(oneshot disabled,critical),用户组(group,user)。

以surfaceflinger为例:

service surfaceflinger /system/bin/surfaceflinger    

class main    

user system    

group graphics    

onrestart restart zygote

它的类别是main,用户是system,属于graphics ,且没有声明disabled,所以在启动main这个类别的时候,surfaceflinger就会被启动。

main类别是在哪里启动的呢?

搜索class_start关键字,在On boot的时候,就会启动了

on boot

  #省略无关.....

 class_start core    

 class_start main

readme中对class_start有如下说明:

class_start <serviceclass> 

Start all services of the specified class if they are   not already running.

class_stop <serviceclass> 

Stop all services of the specified class if they are   currently running. 

所以,在系统启动触发boot这个trigger之后,core和main类别的没有声明为disabled的守护进程就被系统启动了,

具体的过程还得去看init对init.rc文件的解析过程,暂且放着。

那么还有一个疑问,那些声明了为disabled的守护进程是怎么启动的呢?

以Bootanimation为例:

service bootanim /system/bin/bootanimation    

class main    

user graphics    

group graphics    

disabled    

oneshot

它也是main组别的,用户和组均是graphics,且是d

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值