Kernel and user

Source: Internet
Author: User
Kernel mode and user mode-General Linux technology-Linux programming and kernel information. The following is a detailed description. 1. kernel and user

When a task (process) executes a system call and is executed in the kernel code, it is called that the process is in the kernel running state (or kernel state for short ). At this time, the processor is executed in the kernel code with the highest privilege level (level 0. When the process is in the kernel state, the kernel stack of the current process is used for the executed kernel code. Each process has its own kernel stack. When a process executes the user's code, it says it is in the user running state (user state ). That is, the processor runs in the (3) User code with the lowest privilege level. When a user program is being executed and suddenly interrupted, the user program can also be symbolically called in the kernel state of the process. Because the interrupt handler will use the kernel stack of the current process. This is similar to the status of processes in the kernel state.

In short:

1. enter the core state when calling the system. Linux's hardware operations can only be performed in the core state, which can be controlled by writing a driver. Operating hardware in user mode will cause core dump.

2. differentiate between system calls and general functions. System calls are provided by the kernel, such as read (), write (), and open. General functions are provided by the function libraries in the software package, such as sin () and cos. There is no difference in syntax between the two.

3. generally, system calls run in the core state and functions run in the user state. However, some functions use system calls (such as fopen) internally. such functions enter the core state when calling the system call, while others run in the user state.

2. process context and interrupt context

The processor is always in one of the following states:

1. the kernel State runs in the process context. the kernel indicates that the process runs in the kernel space;

2. the kernel State runs in the interrupt context. the kernel indicates that the hardware runs in the kernel space;

3. user state, running in user space.

The user space application enters the kernel space through the system call. At this time, the process in the user space needs to pass a lot of variables and parameter values to the kernel, and some register values and variables of the user process should also be stored during the kernel running. The so-called "process context" can be seen as the parameters passed to the kernel by the user process, as well as the entire set of variables and register values to be stored in the kernel and the environment at that time.

The hardware calls the interrupt handler through the trigger signal and enters the kernel space. In this process, some hardware variables and parameters must also be passed to the kernel. the kernel uses these parameters for interrupt processing. The so-called "interrupt context" can also be seen as the parameters passed by the hardware and other environments that the kernel needs to save (mainly the process environment currently interrupted ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.