日期:2014-05-16  浏览次数:20726 次

怎么找文件?
内核的初始化代码位于   init/main.c   中的   static   int   init(void   *   unused)函数中。
看书中有一段上面的话,这个main.c文件在系统的什么地方?

------解决方案--------------------
这个文件在你的本机上不一定有:因为你的本机不一定装有源码:
建议你去下一个:很多地方都有下,下了之后,你直接在/init/mail.c里就可以了找到了:
摘了一部分:
static int init(void * unused)
{
lock_kernel();
/*
* init can run on any cpu.
*/
set_cpus_allowed(current, CPU_MASK_ALL);
/*
* Tell the world that we 're going to be the grim
* reaper of innocent orphaned children.
*
* We don 't want people to have to make incorrect
* assumptions about where in the task array this
* can be found.
*/
init_pid_ns.child_reaper = current;

cad_pid = task_pid(current);

smp_prepare_cpus(max_cpus);

do_pre_smp_initcalls();

smp_init();
sched_init_smp();

cpuset_init_smp();

do_basic_setup();

/*
* check if there is an early userspace init. If yes, let it do all
* the work
*/

if (!ramdisk_execute_command)
ramdisk_execute_command = "/init ";

if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
ramdisk_execute_command = NULL;
prepare_namespace();
}

/*
* Ok, we have completed the initial bootup, and
* we 're essentially up and running. Get rid of the
* initmem segments and start the user-mode stuff..
*/
free_initmem();
unlock_kernel();
mark_rodata_ro();
system_state = SYSTEM_RUNNING;
numa_default_policy();

if (sys_open((const char __user *) "/dev/console ", O_RDWR, 0) < 0)
printk(KERN_WARNING "Warning: unable to open an initial console.\n ");

(void) sys_dup(0);
(void) sys_dup(0);

if (ramdisk_execute_command) {
run_init_process(ramdisk_execute_command);
printk(KERN_WARNING "Failed to execute %s\n ",
ramdisk_execute_command);
}

/*
* We try each of these until one succeeds.
*
* The Bourne shell can be used instead of init if we are
* trying to recover a really broken machine.
*/
if (execute_command) {
run_init_process(execute_command);
printk(KERN_WARNING "Failed to execute %s. Attempting "
"defaults...\n ", execute_command);
}
run_init_process( "/sbin/init ");
run_init_process( "/etc/init ");
run_init_process( "/bin/init ");
run_init_process( "/bin/sh ");

panic( "No init found. Try passing init= option to kernel. ");
}