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, &init_pid_ns);