Concept
Kernel Space-User space
Kernel space and user space are virtual spaces, but not coincident, each process can enter the kernel through system calls, kernel space is all processes and kernel sharing, the user space of different processes is independent of each other. Kernel is the core of the OS, independent of ordinary applications, with access to protected memory space and underlying hardware devices.
- Kernel function module (operating system, driver, etc.) running in kernel space, running at the highest level (level 0, kernel state);
- The application runs in user space, runs at the lowest level (level 3, user state);
Process Context-Interrupt context
Contextual Context: In short, the state of the environment.
Context switch contexts Switch : cpu the event that occurs when the current running task is transferred to another ready task, This includes the running environment that holds the current task's run environment and the recovery readiness task.
- < Span class= "token lf" > The application of user space enters kernel space through system calls. The process of user space is to pass the values of variables and parameters to the kernel, while the kernel state also saves the user process's register value, variables, etc. The so-called " process Context ", the parameters that the user process passes to the kernel, the variables and register values that the kernel will save, and the current environment.
- The hardware causes the kernel to call the interrupt handler into kernel space by triggering the signal. Hardware variables, parameters to pass to the kernel, the kernel through these parameters to interrupt processing. The so-called " Interrupt Context ", the parameters that the hardware passes to the kernel and the current environment in which the kernel needs to be saved (mainly the current context of the process being interrupted).
The interrupt context does not belong to any process, and the interrupt context and process context cannot occur at the same time. Kernel code running in the process context is preempted, but the interrupt context runs until the end and is not preempted.
The processor is always in one of the following states:
- Kernel state, running in the process context, the kernel represents the process running in the kernel space;
- Kernel state, running in the interrupt context, the kernel represents the hardware running in the kernel space;
- user state, running in user space;
reference : User space and kernel space, process context and interrupt context [summary];
Linux Primary knowledge