Embedded 版 (精华区)

发信人: snows (花自飘零水自流), 信区: Embedded
标  题: The init() Function  
发信站: 哈工大紫丁香 (2004年03月16日13:29:39 星期二), 站内信件

The init() Function
Init() is located in init/main.c.

Init() completes the kernel's boot process by calling do_basic_setup() to
initialize the kernel's PCI and network features. The remaining memory
allocated for initialization is discarded, scheduling is enabled, the
standard input, output and error streams are created, and prepare_namespace()
is called to mount the root filesystem.

With the root filesystem in place, init() runs execve() to launch the program
/sbin/init, if it exists. If a valid program name is provided with the
init=<programname> command line option, init() will execve() that program
instead. If a suitable startup program cannot be found (the kernel also tries
"/bin/init" and "/bin/sh"), the kernel panics and halts.

The code for init() is shown in Figure 8.

static int init(void * unused)
{
   lock_kernel();
   do_basic_setup();

   prepare_namespace();

   free_initmem();
   unlock_kernel();

   if (open("/dev/console", O_RDWR, 0) < 0)
      printk("Warning: unable to open an initial console.\n");

   (void) dup(0);
   (void) dup(0);

   if (execute_command) execve(execute_command,argv_init,envp_init);
   execve("/sbin/init", argv_init, envp_init);
   execve("/bin/init",argv_init,envp_init);
   execve("/bin/sh",argv_init,envp_init);
   panic("No init found.  Try passing init= option to kernel.");
}

Figure 8. The init() function.
  

--
-
 ╭────────────────────────────╮
 │   风萧传瑟声,叶落根深处,青阶入野无归途,他乡不知顾   │
 │   泣下问和谁,叹者行已暮,寒眉傲骨今尚在,奈何入凡土   │
 ╰────────────────────────────╯
                                                                             

※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.229.154]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:8.757毫秒