当前位置:网站首页>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.
边栏推荐
- MySQL3
- MongoDB construction and basic operations
- 原生js实现多选框全部选中和取消效果
- If capturable=False, state_steps should not be CUDA tensors
- [GYCTF2020]EasyThinking
- Three handshake and four wave in tcp
- 手把手基于YOLOv5定制实现FacePose之《YOLO结构解读、YOLO数据格式转换、YOLO过程修改》
- 面试汇总:为何大厂面试官总问 Framework 的底层原理?
- Pytorch使用和技巧
- Introduction to JVM class loading
猜你喜欢
The use of pytorch: temperature prediction using neural networks
【Endnote】Word插入自定义形式的Endnote文献格式
ORA-01105 ORA-03175
金九银十面试跳槽季;你准备好了吗?
Getting Started with Kubernetes Networking
[How to smash wool according to the music the couple listens to during the Qixi Festival] Does the background music affect the couple's choice of wine?
A new technical director, who calls DDD a senior, is convinced
4. PCIe interface timing
VOC格式数据集转COCO格式数据集
B站7月榜单丨飞瓜数据B站UP主排行榜发布!
随机推荐
ORA-00257
Software Testing Interview Questions: Qualifying Criteria for Software Acceptance Testing?
torch.autograd.grad finds the second derivative
[FreeRTOS] FreeRTOS and stm32 built-in stack occupancy
执掌图表
Matlab uses plotting method for data simulation and simulation
如何创建rpm包
居民用水问题
JUC thread pool (1): FutureTask use
[GYCTF2020]EasyThinking
JWT简单介绍
测试工作这么难找吗?今年32,失业2个月,大龄测试工程师接下来该拿什么养家?
方法重写与Object类
【Endnote】Word插入自定义形式的Endnote文献格式
仅3w报价B站up主竟带来1200w播放!品牌高性价比B站投放标杆!
Lattice PCIe Learning 1
Pytorch使用和技巧
4. PCIe 接口时序
Difference between MBps and Mbps
(十七)51单片机——AD/DA转换