当前位置:网站首页>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.
边栏推荐
- Getting Started with Kubernetes Networking
- 新来个技术总监,把DDD落地的那叫一个高级,服气
- 硬实力和软实力,哪个对测试人来说更重要?
- Software Testing Interview Questions: What Are the Types of Software Testing?
- Gartner Hype Cycle:超融合技术将在2年内到达“生产力成熟期”
- Three handshake and four wave in tcp
- 二叉树[全解](C语言)
- Bit rate vs. resolution, which one is more important?
- 5. PCIe official example
- Use of pytorch: Convolutional Neural Network Module
猜你喜欢

Lattice PCIe Learning 1

方法重写与Object类

迅睿cms网站搬迁换了服务器后网站不能正常显示

【FreeRTOS】FreeRTOS与stm32内置堆栈的占用情况
![[FreeRTOS] FreeRTOS and stm32 built-in stack occupancy](/img/33/3177b4c3de34d4920d741fed7526ee.png)
[FreeRTOS] FreeRTOS and stm32 built-in stack occupancy

ora-01105 ora-03175

第09章 性能分析工具的使用【2.索引及调优篇】【MySQL高级】

oracle create user

手把手基于YOLOv5定制实现FacePose之《YOLO结构解读、YOLO数据格式转换、YOLO过程修改》

LiveVideoStackCon 2022 Shanghai Station opens tomorrow!
随机推荐
Dynamic Programming/Knapsack Problem Summary/Summary - 01 Knapsack, Complete Knapsack
day14--postman接口测试
活动推荐 | 快手StreamLake品牌发布会,8月10日一起见证!
KingbaseES V8 GIS数据迁移方案(2. Kingbase GIS能力介绍)
GCC:屏蔽动态库之间的依赖
为什么他们选择和AI恋爱?
Method Overriding and Object Class
Software Testing Interview Questions: What is Software Testing?The purpose and principle of software testing?
torch.autograd.grad求二阶导数
GCC:编译时库路径和运行时库路径
从一次数据库误操作开始了解MySQL日志【bin log、redo log、undo log】
二叉树[全解](C语言)
第十一章 开关级建模
2022 Hangzhou Electric Power Multi-School Session 3 K Question Taxi
超越YOLO5-Face | YOLO-FaceV2正式开源Trick+学术点拉满
张驰咨询:揭晓六西格玛管理(6 Sigma)长盛不衰的秘密
BC(转)[js]js计算两个时间相差天数
Methods commonly used interface automation test framework postman tests
接口自动化测试框架postman tests常用方法
【TA-霜狼_may-《百人计划》】图形4.3 实时阴影介绍