I searched on the internet for which is the first process which gets executed upon system startup.
我在互联网上搜索了第一个在系统启动时执行的进程。
I found two answers which are init
and sched
. What is it really?
我找到了两个init和sched的答案。真的是什么?
Which gets executed first? sched
process or init
process?
首先执行哪个? sched进程或init进程?
5 个解决方案
#1
12
Typically it is the init
process, the path of which is hard coded into the kernel itself. init
performs very low level functions like starting upstart
in the case of Ubuntu (prior to 15.40) or systemd
in the case of Ubuntu 15.04 and later, Arch, Fedora, and others, which load the remaining processes and setup. Note that the system is not done booting when init
runs - that is a common misconception. In fact, init
sets up your login screen and other related tasks. Here's a WikiPedia page on init
: https://en.wikipedia.org/wiki/Linux_startup_process#SysV_init
通常它是init进程,其路径被硬编码到内核本身。 init执行非常低级别的功能,例如在Ubuntu(15.40之前)的情况下启动upstart,或者在Ubuntu 15.04及更高版本,Arch,Fedora等的情况下启动系统,它们加载剩余的进程和设置。请注意,在init运行时系统没有完成引导 - 这是一种常见的误解。实际上,init会设置您的登录屏幕和其他相关任务。这是关于init的WikiPedia页面:https://en.wikipedia.org/wiki/Linux_startup_process#SysV_init
Init is the father of all processes. Its primary role is to create processes from a script stored in the file /etc/inittab. This file usually has entries which cause init to spawn gettys on each line that users can log in. It also controls autonomous processes required by any particular system. A run level is a software configuration of the system which allows only a selected group of processes to exist. The processes spawned by init for each of these run levels are defined in the /etc/inittab file.
Init是所有进程的父亲。它的主要作用是从存储在文件/ etc / inittab中的脚本创建进程。此文件通常具有导致init在用户可以登录的每一行上生成gettys的条目。它还控制任何特定系统所需的自治进程。运行级别是系统的软件配置,其仅允许存在选定的一组进程。 init为每个运行级别生成的进程在/ etc / inittab文件中定义。
However, the Linux kernel does start the scheduler but it is not in userspace, which is what most people associate as the home for a process. Also, the Bourne Shell (/bin/sh
) can be substituted if the init
is missing or cannot be called. You can also in theory substitute it for any executable by using the init=*some path here*
Linux kernel boot option.
但是,Linux内核确实启动了调度程序,但它不在用户空间中,这是大多数人将其关联为进程的主页。此外,如果init丢失或无法调用,则可以替换Bourne Shell(/ bin / sh)。理论上,您也可以使用此处的init = * some path * Linux内核引导选项将其替换为任何可执行文件。
#2
6
Its sched
, as per Linux 3.13 start kernel() first calls sched_init() and runs first user space process init i.e rest_init() creates a kernel thread passing another function kernel_init() as the entry point and kernel goes to idle unless called.
它的sched,根据Linux 3.13启动kernel()首先调用sched_init()并运行第一个用户空间进程init,即rest_init()创建一个内核线程传递另一个函数kernel_init()作为入口点,内核进入空闲状态,除非被调用。
start_kernel() {
...
sched_init();
rest_init(); calls function kernel_init();
}
#3
2
The kernel at least has one runnable process, which is known as the idle task, swapper, init_task and sched. They are different names of the same process whose pid is 0. This init_task is a global variable of kernel, so it have a fixed address, you can see it from System.map by command grep 'D init_task' /boot/System.map-*
. The address wouldn't change unless you recompile the kernel.
内核至少有一个可运行的进程,称为idle task,swapper,init_task和sched。它们是pid为0的同一进程的不同名称。这个init_task是内核的全局变量,所以它有一个固定的地址,你可以通过命令grep''d init_task'/boot/System.map从System.map看到它。 - *。除非重新编译内核,否则地址不会改变。
The program init whose pid is 1, spawned by init_task(pid 0). In Ubuntu, The program init is the Upstart process management daemon, while in other systems, it could be systemd. The address of init changed every time while system rebooting.
由pid为1的程序init,由init_task(pid 0)生成。在Ubuntu中,程序init是Upstart进程管理守护进程,而在其他系统中,它可以是systemd。每次系统重启时,init的地址都会更改。
So, process 0 run first, then spawn process 1.
因此,进程0首先运行,然后生成进程1。
#4
1
You can try
你可以试试
pstree 0
it will show the all process hierarchy in tree form right from the children on sched
process (PID 0). No doubt init
is the parent of all process but sched
gets executed before init
and spaws both init
and kthread
.
它将直接显示树形式的所有流程层次结构,直接来自子流程上的子流程(PID 0)。毫无疑问,init是所有进程的父进程,但是在init之前执行sched并且生成init和kthread。
You can also see the PPID (i.e. process id of parent process ) using:
您还可以使用以下命令查看PPID(即父进程的进程ID):
ps -eaf
You will notice it to be 0 for both init
and kthread
.
你会注意到init和kthread都是0。
#5
0
Swapper is the first process running. It has pid 0.
Swapper是第一个运行的进程。它有pid 0。
#1
12
Typically it is the init
process, the path of which is hard coded into the kernel itself. init
performs very low level functions like starting upstart
in the case of Ubuntu (prior to 15.40) or systemd
in the case of Ubuntu 15.04 and later, Arch, Fedora, and others, which load the remaining processes and setup. Note that the system is not done booting when init
runs - that is a common misconception. In fact, init
sets up your login screen and other related tasks. Here's a WikiPedia page on init
: https://en.wikipedia.org/wiki/Linux_startup_process#SysV_init
通常它是init进程,其路径被硬编码到内核本身。 init执行非常低级别的功能,例如在Ubuntu(15.40之前)的情况下启动upstart,或者在Ubuntu 15.04及更高版本,Arch,Fedora等的情况下启动系统,它们加载剩余的进程和设置。请注意,在init运行时系统没有完成引导 - 这是一种常见的误解。实际上,init会设置您的登录屏幕和其他相关任务。这是关于init的WikiPedia页面:https://en.wikipedia.org/wiki/Linux_startup_process#SysV_init
Init is the father of all processes. Its primary role is to create processes from a script stored in the file /etc/inittab. This file usually has entries which cause init to spawn gettys on each line that users can log in. It also controls autonomous processes required by any particular system. A run level is a software configuration of the system which allows only a selected group of processes to exist. The processes spawned by init for each of these run levels are defined in the /etc/inittab file.
Init是所有进程的父亲。它的主要作用是从存储在文件/ etc / inittab中的脚本创建进程。此文件通常具有导致init在用户可以登录的每一行上生成gettys的条目。它还控制任何特定系统所需的自治进程。运行级别是系统的软件配置,其仅允许存在选定的一组进程。 init为每个运行级别生成的进程在/ etc / inittab文件中定义。
However, the Linux kernel does start the scheduler but it is not in userspace, which is what most people associate as the home for a process. Also, the Bourne Shell (/bin/sh
) can be substituted if the init
is missing or cannot be called. You can also in theory substitute it for any executable by using the init=*some path here*
Linux kernel boot option.
但是,Linux内核确实启动了调度程序,但它不在用户空间中,这是大多数人将其关联为进程的主页。此外,如果init丢失或无法调用,则可以替换Bourne Shell(/ bin / sh)。理论上,您也可以使用此处的init = * some path * Linux内核引导选项将其替换为任何可执行文件。
#2
6
Its sched
, as per Linux 3.13 start kernel() first calls sched_init() and runs first user space process init i.e rest_init() creates a kernel thread passing another function kernel_init() as the entry point and kernel goes to idle unless called.
它的sched,根据Linux 3.13启动kernel()首先调用sched_init()并运行第一个用户空间进程init,即rest_init()创建一个内核线程传递另一个函数kernel_init()作为入口点,内核进入空闲状态,除非被调用。
start_kernel() {
...
sched_init();
rest_init(); calls function kernel_init();
}
#3
2
The kernel at least has one runnable process, which is known as the idle task, swapper, init_task and sched. They are different names of the same process whose pid is 0. This init_task is a global variable of kernel, so it have a fixed address, you can see it from System.map by command grep 'D init_task' /boot/System.map-*
. The address wouldn't change unless you recompile the kernel.
内核至少有一个可运行的进程,称为idle task,swapper,init_task和sched。它们是pid为0的同一进程的不同名称。这个init_task是内核的全局变量,所以它有一个固定的地址,你可以通过命令grep''d init_task'/boot/System.map从System.map看到它。 - *。除非重新编译内核,否则地址不会改变。
The program init whose pid is 1, spawned by init_task(pid 0). In Ubuntu, The program init is the Upstart process management daemon, while in other systems, it could be systemd. The address of init changed every time while system rebooting.
由pid为1的程序init,由init_task(pid 0)生成。在Ubuntu中,程序init是Upstart进程管理守护进程,而在其他系统中,它可以是systemd。每次系统重启时,init的地址都会更改。
So, process 0 run first, then spawn process 1.
因此,进程0首先运行,然后生成进程1。
#4
1
You can try
你可以试试
pstree 0
it will show the all process hierarchy in tree form right from the children on sched
process (PID 0). No doubt init
is the parent of all process but sched
gets executed before init
and spaws both init
and kthread
.
它将直接显示树形式的所有流程层次结构,直接来自子流程上的子流程(PID 0)。毫无疑问,init是所有进程的父进程,但是在init之前执行sched并且生成init和kthread。
You can also see the PPID (i.e. process id of parent process ) using:
您还可以使用以下命令查看PPID(即父进程的进程ID):
ps -eaf
You will notice it to be 0 for both init
and kthread
.
你会注意到init和kthread都是0。
#5
0
Swapper is the first process running. It has pid 0.
Swapper是第一个运行的进程。它有pid 0。