linux - 内核进程和内核模式的疑问
天蓬老师
天蓬老师 2017-04-17 13:45:28
0
2
424

我在看Unix V6的源码剖析的书,关于内核模式和内核进程有点混淆,请问:
系统调用或中断发生时,是用户进程自己转入内核模式处理?还是由内核进程来处理,处理完再把结果给用户进程?
据我所知 proc[0]和proc[1]是内核进程,swtch函数处理时切换到了proc[0]

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
迷茫

Because many designs of Linux are similar to Unix, here are a few points I learned from "Linux Kernel Design and Implementation". I hope it will be a little helpful to your understanding.

Kernel mode (also called kernel state) means that the current code instructions are executed in the kernel space. Relatively speaking, it is user mode, that is, the programs we write run in user space.

If a user space process wants to access or operate hardware, it must let the kernel do it. The system call is actually the process requesting the kernel to do something. When a system call occurs, the process falls into the kernel state. At this time, the kernel is in the process context. The kernel knows the process that currently initiates the system call and its information, and then the kernel does things on behalf of the process.

System calls are implemented using soft interrupts, that is, the user space process initiates a system call, which actually generates a soft interrupt, allowing the CPU to enter the kernel's interrupt handler, thus entering the kernel state. When the system call ends, the kernel is responsible for switching back to user space, and the process continues to execute in user space (of course the kernel knows how to switch back to user space, because the data and processes in user space are managed by the kernel). System call parameters and return values ​​are copied between user space and kernel space.

Each processor (each core) has a kernel thread (or process), and the soft interrupt of the system call is processed in this kernel thread.

Kernel threads are a mechanism that assists in interrupt handling.

洪涛

I have also been looking at unix operating systems recently. When an interrupt occurs, the kernel schedules the process, and the process itself cannot sense the interrupt.
The system call is equivalent to calling a piece of code that is not the process itself, but the system code, and then enters the core state.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template