在systemd环境中,当我执行ps -auxf时,我看到kthread的PID为2,而systemd分配了PID 1.
那么,谁将PID 2分配给kthread,为什么当kthread被称为systemd时它会获得PID 2?
解决方法:
我不认为kthreadd正在启动init(在你的情况下符号链接到systemd).
init由内核初始化启动. kthreadd刚刚开始.请参阅此kernel threads wikipage,对于Linux 4.2,其文件init/main.c,函数rest_init,在第397行附近,您可以看到:
/*
* 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);
所以kthreadd没有启动init,但是两者都是在调度之前在内核中启动的,所以在开始执行之前.
静态kernel_init函数(init/main.c的第930-975行)具有以下特点:
if (execute_command) {
ret = run_init_process(execute_command);
if (!ret)
return 0;
panic("Requested init %s failed (error %d).",
execute_command, ret);
}
if (!try_to_run_init_process("/sbin/init") ||
!try_to_run_init_process("/etc/init") ||
!try_to_run_init_process("/bin/init") ||
!try_to_run_init_process("/bin/sh"))
return 0;
所以设置init进程(àlaexecve(2) ….)并且有硬连线/ sbin / init等…
并且init
process已经有1年的pid 1(自20世纪70年代的原始Unix以及没有内核线程的旧Linux 1.x内核).这是一个强大的Unix惯例(可能很多软件都依赖于它).您可以使用systemd作为您的初始化进程,但您也可以使用sysvinit或简单地使用bash(有时将init = / bin / bash传递到内核到GRUB以进行修复)或其他内容(例如runit)
原文地址:https://codeday.me/bug/20190824/1708452.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。