当前位置:网站首页>The difference between a process in user mode and kernel mode [exclusive analysis]
The difference between a process in user mode and kernel mode [exclusive analysis]
2022-08-05 01:28:00 【alibaba_Zhang Wuji】
Basic knowledge first:
Basic
When the kernel creates a process, it will create a corresponding stack for the process.
Each process will have two stacks, a user stack, which exists in user space, and a kernel stack, which exists in kernel space.
When the process is running in the user space, the content in the CPU register is the user stack address, and the user stack is used.
When the process is in the kernel space, the content in the CPU register is the address in the kernel stack space, and the kernel stack is used.
Switching process:
When a system call occurs, the user-mode program initiates a system call.The user mode program has insufficient permissions, so the execution will be interrupted. After the interrupt occurs, the program executed by the current CPU will be interrupted and jump to the interrupt handler.The kernel program starts executing, that is, starts processing system calls.After the kernel processing is completed, this will interrupt again and switch back to user mode work.
Difference:
The most important difference is the difference in the level of privilege, that is, the difference in power.运行在用户态下的程序不能直接访问操作系统内核数据结构和程序
系统中执行的程序大部分时间运行在用户态,在其需要操作系统帮助完成某些它没有权力和能力When the work is done, it switches to kernel mode.
3 ways to switch from user mode to kernel mode
1. System call
This is a way for the user mode process to actively request to switch to the kernel mode. The user mode process applies for using the service program provided by the operating system through the system call to complete the work, such asFork() in the previous example actually executes a system call to create a new process.The core of the system call mechanism is implemented by using an interrupt specially opened by the operating system for the user, such as the int 80h interrupt of Linux.
2. Exception
When the CPU is executing a program running in user mode, some unpredictable exception occurs, which will trigger the current running process to switch to the kernel-related program that handles this exception, it also goes to the kernel state, such as page fault exception.
3. Interruption of peripheral devices
When the peripheral device completes the operation requested by the user, it will send a corresponding interrupt signal to the CPU. At this time, the CPU will suspend the execution of the next instruction to be executed and turn to execute and interruptFor the processing program corresponding to the signal, if the previously executed instruction is a program in user mode, then this conversion process will naturally switch from user mode to kernel mode.For example, when the hard disk read and write operations are completed, the system will switch to the hard disk read and write interrupt handler to perform subsequent operations.
边栏推荐
- The principle of NMS and its code realization
- 迅睿cms网站搬迁换了服务器后网站不能正常显示
- ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionExcep
- MySQL学习
- 手把手基于YOLOv5定制实现FacePose之《YOLO结构解读、YOLO数据格式转换、YOLO过程修改》
- GCC:屏蔽动态库之间的依赖
- 【Word】Word公式导出PDF后出现井号括号#()错误
- 张驰咨询:揭晓六西格玛管理(6 Sigma)长盛不衰的秘密
- GCC:头文件和库文件的路径
- Methods commonly used interface automation test framework postman tests
猜你喜欢
随机推荐
软件基础的理论
Dynamic Programming/Knapsack Problem Summary/Summary - 01 Knapsack, Complete Knapsack
工具类总结
手把手基于YOLOv5定制实现FacePose之《YOLO结构解读、YOLO数据格式转换、YOLO过程修改》
[FreeRTOS] FreeRTOS and stm32 built-in stack occupancy
自定义线程池
Lattice PCIe 学习 1
The use of pytorch: temperature prediction using neural networks
活动推荐 | 快手StreamLake品牌发布会,8月10日一起见证!
CNI (Container Network Plugin)
Why is this problem reported when installing oracle11
Methods commonly used interface automation test framework postman tests
深度学习:使用nanodet训练自己制作的数据集并测试模型,通俗易懂,适合小白
The principle of NMS and its code realization
JUC thread pool (1): FutureTask use
B站7月榜单丨飞瓜数据B站UP主排行榜发布!
[Redis] Redis installation under Linux
Getting Started with Kubernetes Networking
Helm Chart
10年测试经验,在35岁的生理年龄面前,一文不值









