linux根文件系统init进程分析

init程序本身即busybox:

  1. 配置文件
  2. 解析配置文件
  3. 执行用户程序

程序执行过程:

busybox  ->  init_main

                parse_inittab

                          file = open(INITTAB,"r");  //打开配置文件  /etc/inittab 


                          new_init_action

                                       1、创建一个init_action结构,填充

                                       2、把这个结构放入init_action_list这个链表中

                          run_actions(SYSINIT);

                                        waitfor(a,0);   //执行应用程序,等待他执行完毕

                                                 run(a);   //创建process子进程

                                                 wait(runpid,&status,0);  //等待执行结束

                                        delete_init_action(a);     //在init_action_list链表里删除

                          run_actions(WAIT);

                                        waitfor(a,0);   //执行应用程序,等待他执行完毕

                                                 run(a);   //创建process子进程

                                                 wait(runpid,&status,0);  //等待执行结束

                                        delete_init_action(a);     //在init_action_list链表里删除

                          run_actions(ONCE);//与SYSINIT,WAIT有区别

                                        run(a);   //创建process子进程

                                        delete_init_action(a);     //在init_action_list链表里删除

                          while(1)

                          {

                                runactions(RESPAWN);

                                        if(a->pid == 0)

                                        {

                                                a->pid = run(a);

                                        }

                                run_actions(ASKFIRST);//                     

                                        if(a->pid == 0)

                                        {

                                                a->pid = run(a);                                                           

                                                    打印 Please press Enter to activate this console 

                                                    等待回车

                                                    创建子进程    

                                        }

                                wpid = wait(NULL); //等待子进程退出

                                while(wpid > 0)

                                 {

                                             a->pid = 0;   //退出后,就设置 pid=0;

                                 }

                         }

-------------------------------------------------------------------------------------------------------------

inittab的格式:  (指定程序,何时执行) /etc/inittab

<id>:<runlevels>:<action>:<process>

id =>/dev/id,   用作终端:stdin,stdout,stderr:printf,scanf,err

runlevels: 可完全忽略

action:指定何时执行

process:应用程序的或脚本

-------------------------------------------------------------------------------------------------------------

最小根文件系统:

  1. /dev/console   /dev/null
  2. init->busubox
  3. /etc/inittab
  4. 由配置文件指定的程序
  5. c库
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值