linux 4.12内核学习第一天

D:\linux4.12\linux-4.12.1\arch 

这个目录下放的是各种CPU上电启动的代码,没有具体研究看不大懂

D:\linux4.12\linux-4.12.1\init\main.c

这里是初始化的C语言代码,这里的初始化和体系结构无关,起始函数start_kernel(void)


asmlinkage __visible void __init start_kernel(void)
{
	...
	rest_init();
}

rest_init()是最后一个函数,前面是初始化内核的各种子系统,没有具体研究。

这里看一下rest_init()这个函数

static noinline void __ref rest_init(void)
{
	int pid;

	rcu_scheduler_starting();
	/*
	 * We need to spawn init first so that it obtains pid 1, however
	 * the init task will end up wanting to create kthreads, which, if
	 * we schedule it before we create kthreadd, will OOPS.
	 */
	kernel_thread(kernel_init, NULL, CLONE_FS);
	numa_default_policy();
	pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
	rcu_read_lock();
	kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);
	rcu_read_unlock();
	complete(&kthreadd_done);

	/*
	 * The boot idle thread must execute schedule()
	 * at least once to get things moving:
	 */
	init_idle_bootup_task(current);
	schedule_preempt_disabled();
	/* Call into cpu_idle with preempt disabled */
	cpu_startup_entry(CPUHP_ONLINE);
}

kernel_thread(kernel_init, NULL, CLONE_FS);

创建PID为1的进程,即init进程

pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);

创建PID为2的进程,负责初始化内核的其他线程

init是用户空间第一个进程,负责启动用户程序,用户常用的init程序有sysvinit、busybox init、upstart、systemd、procd。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值