Linux中的特殊进程:idle进程、init进程、kthreadd进程

Linux中的三个特殊进程:

idle进程:

               该进程是Linux中的第一个进程(线程),PID为0;

               idle进程是init进程和kthreadd进程(内核线程)的父进程;

init进程:

               init进程是Linux中第一个用户空间的进程,PID为1;

               init进程是其他用户空间进程的直接或间接父进程;

kthreadd(内核线程):

               kthreadd线程是内核空间其他内核线程的直接或间接父进程,PID为2;

               kthreadd线程负责内核线程的创建工作;

 

idle进程、init进程、kthreadd进程的创建

ARM架构中idle进程的创建

https://elixir.bootlin.com/linux/latest/source/arch/arm64/kernel/head.S#L472

在start_kernel函数中调用了rest_init函数,在rest_init函数中创建了kernel_init、kthreadd内核线程

https://elixir.bootlin.com/linux/latest/source/init/main.c#L674

 

noinline void __ref rest_init(void)
{
	struct task_struct *tsk;
	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.
	 */
	pid = kernel_thread(kernel_init, NULL, CLONE_FS);
	/*
	 * Pin init on the boot CPU. Task migration is not properly working
	 * until sched_init_smp() has been run. It will set the allowed
	 * CPUs for init to the non isolated CPUs.
	 */
	rcu_read_lock();
	tsk = find_task_by_pid_ns(pid, &
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值