BusyBox init及其inittab文件分析
由于BusyBox自身的一些特点,BusyBox init非常适合在嵌入式系统开发中使用,被誉为“嵌入式linux的瑞士军刀”,它可以为嵌入式系统提供只要的init功能,并且通过定制可以做得非常 精炼。inittab是帮助init完成系统配置的主要文件。
/* Line is: "id:runlevel_ignored:action:command" */
|
|
action | 含义 |
sysinit | 为init提供初始化命令脚本的路径 |
respawn | 每当相应的进程终止执行时,重新启动该进程 |
askfirst | 类似respawn,主要用途是减少系统上执行的终端应用程序的数量。它将会促使init在控制台上显示“Please press Enter to active this console”的信息,并在重新启动进程之前等待用户按下“enter”键 |
wait | 告诉init必须等到相应的进程执行完成之后才能继续执行 |
once | 仅执行相应的进程一次,而且不会等待它执行完成 |
ctratldel | 当按下Ctrl+Alt+Delete组合键时,执行相应的进程 |
shutdown | 当系统关机时,执行相应的进程 |
restart | 当init重新启动时,执行相应的进程,通常此处所执行的进程就是init本身 |
|
|
|
|
/* Now run everything that needs to be run */
/* 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 ) ;
}
}
}
更多推荐
所有评论(0)