In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what is the init process in the linux kernel". In the daily operation, I believe that many people have doubts about what the init process is in the linux kernel. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what is the init process in the linux kernel?" Next, please follow the editor to study!
1. The init process has completed the transition from kernel state to user mode:
1. One process has two states:
We are talking about one process and two states here, and we are talking about the transition of the state of the process. First of all, before introducing the transition of this state, let's take a look at what is the init process, which is actually the first process that the linux system runs after startup. (for learning about the process here, you can see the linux application programming album I shared earlier, which has a very detailed introduction). The init process started running in kernel mode, which belongs to a kernel thread, and then he ran a program in user mode and forcibly transferred himself to user mode. Because the init process itself completes the transition from kernel mode to user mode, other subsequent processes can work in user mode.
2. What is done in the kernel state?
The key thing to do in kernel state is to mount the root file system and try to find the init program in user mode. To convert itself to user mode, the init process must run a user-mode application (this application is usually called init). To run this application, you must find the application, and to find it, you must mount the root file system, because all the applications are in the file system. All functions in the kernel source code are below the kernel state, and none of them can be executed without the kernel state. The application must not belong to the kernel source code in order to guarantee that it is in user mode. In other words, the init program we execute here is not with the kernel, it is provided separately. The person who provides this init program is the root file system.
To use an inappropriate analogy, for example, as we all know, to build a house, before that, you must lay the foundation, and then you can start building bricks on the foundation, that is, all kinds of operations.
3. What have you done in the user mode?
Most of the meaningful work of the init process is done in user mode. The significance of init processes to our operating system is that all other user processes are directly or indirectly derived from init processes.
4. How to jump from kernel mode to user mode? Can you come back?
When the init process is in kernel state, an application that performs a user-space compiled connection through a function kernel_execve jumps to user mode. Note that the process number has not changed during this jump, so it has always been process 1. This jump process is one-way, that is, once the init program is executed and transferred to the user mode, the entire operating system is really running, and then it can only work in the user mode. If you want to enter the kernel state in the user mode, you have to take API. This is why we often see that the general framework of the operating system is described like this:
Upper layer: indicates our application, in linux we will have the corresponding api (or write our own)
Middle tier: it is our kernel, that is, the operating system.
The bottom layer: the actual hardware circuit (of course, there is a startup program between os and hardware, which is often called uboot).
The specific kernel_execve functions are as follows (whether you like it or not, for the time being, let us feel rationally what it feels like to see the linux kernel code for the first time, which is mainly for those who come into contact with linux code for the first time. ):
Int kernel_execve (const char * filename, char * const argv [], char * const envp [])
{
Struct pt_regs regs
Int ret
Memset (& regs, 0, sizeof (struct pt_regs))
Ret = do_execve ((char *) filename, (char _ _ user * _ user *) argv
(char _ user * _ user *) envp, & regs)
If (ret
< 0) goto out; /* * Save argc to the register structure for userspace. */ regs.ARM_r0 = ret; /* * We were successful. We won't be returning to our caller, but * instead to user space by manipulating the kernel stack. */ asm( "add r0, %0, %1\n\t" "mov r1, %2\n\t" "mov r2, %3\n\t" "bl memmove\n\t" /* copy regs to top of stack */ "mov r8, #0\n\t" /* not a syscall */ "mov r9, %0\n\t" /* thread structure */ "mov sp, r0\n\t" /* reposition stack pointer */ "b ret_to_user" : : "r" (current_thread_info()), "Ir" (THREAD_START_SP - sizeof(regs)), "r" (®s), "Ir" (sizeof(regs)) : "r0", "r1", "r2", "r3", "ip", "lr", "memory"); out: return ret; } 二、init进程构建了用户交互界面: 在上面也说了,在init进程切换到用户状态后,以后对操作系统操作的话就能只能在用户状态下操作了,而这各种操作也就是我们的进程操作了,和windows里面的实际应用程序一样,一个程序就是一个进程,比如我们在windows任务管理器里面就可以看到如下图所示:In our linux system, after the init process is transformed into the user state, there are some process operations that we are familiar with: the login process, the command line process, the shell process (shell, which we are all familiar with, the human-computer interaction image interface), and the shell process will start other user processes.
At this point, the study of "what is the init process in the linux kernel" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.