The difference between the init function and the init process is

  
.

Because the kernel identifier of the init() function and the process identifier of the init process are both 1, they are called init, so the init() function and the init process are easy to conceptualize. Unclear.

The main difference:

1, the init() function is part of the kernel code, runs in kernel mode and is part of the stand-alone executable code.

2, init process in the Linux operating system
is a special process, 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 user mode. Its code is not part of the kernel itself, but is stored in the image of the executable on the hard disk, no different from other user processes.

Process No. 0--> Kernel Thread No. 1->> Kernel Process No. 1-->init Process (User Process No. 1)

Process No. 0: This is the system A process that is automatically formed at boot time is actually the kernel itself. It is the ancestor of all the processes that are later produced in the system. When the kernel system completes its own initialization, the kernel itself calls the function kernel_thread(), which creates the first kernel thread using the int 0x80 system call.

No. 1 kernel thread: The so-called kernel thread, in Linux system refers to the process without virtual storage space, the kernel thread can directly use the physical address space, running in the kernel state. After the soft interrupt system call returns, 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 to be the parent process, the kernel itself, which is the process number 0. Otherwise it is the first kernel thread created by the kernel. So this thread is the number 1 thread.

No. 1 kernel process: If it is the kernel thread No. 1, the program controls the subroutine to directly execute the init() function. Then, the No. 1 thread will evolve into the No. 1 kernel process.

init process: The init() function calls execve() to load the executable program init() from the file /etc/inittab and execute it. From then on, the kernel process of the init() function evolves to the init process. . In other words, the init process is generated by the init() function. The fork() is not used in this evolution, so the process identifier of the init process is still the identifier 1 of the kernel process number 1. Seeing this, I suddenly remembered that in the embedded root file system, I also executed the init thread of the kernel first. The thread will execute the script. /linuxrc. At the end of the ./linuxrc: execve /sbin/init, go to execute the user. The init process of the space, which will execute the script inittab (if any).

Copyright © Windows knowledge All Rights Reserved