Because the kernel thread that executes the init () function and the process identifier of the INIT process are both 1, and they are also called init, The init () function and the INIT process are prone to conceptual ambiguity.
Main differences:
1. The init () function is the kernelCodeIs a part of the independent executable code.
2. The INIT process is a special process in the Linux operating system. It is the first user process started and run by the kernel, so it is not running in the kernel state, instead, it runs in the user State. Its code is not a part of the kernel itself, but is stored in the image of executable files on the hard disk, which is no different from other user processes.
Process 0 --> kernel thread 1 --> kernel process 1 --> INIT process (user process 1)
Process no. 0: this is a process automatically formed during system boot, which is actually the kernel itself. It is the ancestor of all later processes in the system. After the kernel system completes its own initialization, the kernel itself calls the kernel_thread () function, which uses the int 0x80 system call to create the first kernel thread.
Kernel thread 1: A kernel thread is a process without virtual storage space in Linux. The kernel thread can directly use the physical address space and run in the kernel state. After a Soft Interrupt System Call is returned, the Parent and Child processes are determined by comparing the values of the ESP and ESI registers. If the value of the ESP register is equal to the value of the ESI register, the system considers it as the parent process, namely the kernel itself, and it is the process no. 0. Otherwise, it is the first kernel thread created by the kernel. Therefore, this thread is thread 1.
Kernel process 1: If it is a kernel thread 1,ProgramControl this subroutine to directly execute the init () function. Then, thread 1 will evolve into the kernel process of thread 1.
INIT process: the init () function calls execve () to load and execute the executable program Init () from the file/etc/inittab, and then execute Init () the kernel process of function 1 has evolved into the INIT process. That is to say, the INIT process is generated by the init () function. Fork () is not used in this evolution. Therefore, the process identifier of the INIT process is still the identifier 1 of kernel process 1.
I suddenly remembered that in the embedded root file system, the init thread that first executes the kernel will execute the script./linuxrc. At the end of./linuxrc, execve /Sbin/init: transfers the INIT process of the user space to execute the script inittab (if any ).