当前位置:首页 > 单片机 > 单片机
[导读]1.启动内核启动应用程序/linuxrcbusyboxini.cinit_main设置信号处理函数初始化控制台parse_inittab解析inittab1.1.解析inittabfile=open(INITTAB,“r”); //打开配置文件/etc/inittabnew_init_action//1创建一个init

1.启动

内核启动应用程序/linuxrc

busyboxini.c

init_main

设置信号处理函数

初始化控制台

parse_inittab解析inittab

1.1.解析inittab

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

new_init_action

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

//2把结构放入init_action_list链表

默认配置

::sysinit:/etc/init.d/rcS

::askfirst:/bin/sh

tty2::askfirst:/bin/sh

tty3::askfirst:/bin/sh

tty4::askfirst:/bin/sh

::ctrlaltdel:/sbin/reboot

::shutdown:/sbin/swapoff-a

::shutdown:/bin/umount-a-r

::restart:/sbin/init


1.2.运行


/*Firstrunthesysinitcommand*/

run_actions(SYSINIT);

/*Nextrunanythingthatwantstoblock*/

run_actions(WAIT);

/*Nextrunanythingtoberunonlyonce*/

run_actions(ONCE);

/*Nowruntheloopingstufffortherestofforever*/

while(1){

/*runtherespawn/askfirststuff*/

run_actions(RESPAWN|ASKFIRST);

/*Don'tconsumeallCPUtime--sleepabit*/

sleep(1);

/*Waitforanychildprocesstoexit*/

wpid=wait(NULL);

while(wpid>0){

/*Findoutwhodiedandcleanuptheircorpse*/

for(a=init_action_list;a;a=a->next){

if(a->pid==wpid){

/*Setthepidto0sothattheprocessgets

*restartedbyrun_actions()*/

a->pid=0;

message(L_LOG,"process'%s'(pid%d)exited."

"Schedulingforrestart.",

a->command,wpid);

}

}

/*seeifanyoneelseiswaitingtobereaped*/

wpid=wait_any_nohang(NULL);

}

}



本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭