1. 启动
内核启动应用程序/linuxrc
busybox ini.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. 运行
/* first run the sysinit command */
run_actions(sysinit);
/* next run anything that wants to block */
run_actions(wait);
/* next run anything to be run only once */
run_actions(once);
/* now run the looping stuff for the rest of forever */
while (1) {
/* run the respawn/askfirst stuff */
run_actions(respawn | askfirst);
/* don't consume all cpu time -- sleep a bit */
sleep(1);
/* wait for any child process to exit */
wpid = wait(null);
while (wpid > 0) {
/* find out who died and clean up their corpse */
for (a = init_action_list; a; a = a->next) {
if (a->pid == wpid) {
/* set the pid to 0 so that the process gets
* restarted by run_actions() */
a->pid = 0;
message(l_log, "process '%s' (pid %d) exited. "
"scheduling for restart.",
a->command, wpid);
}
}
/* see if anyone else is waiting to be reaped */
wpid = wait_any_nohang(null);
}
}
『本文转载自网络,u球体育app下载的版权归原作者所有,如有侵权请联系删除』