当前位置:网站首页>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.
边栏推荐
- Are testing jobs so hard to find?I am 32 this year and I have been unemployed for 2 months. What should an older test engineer do next to support his family?
- pytorch的使用:使用神经网络进行气温预测
- 阶段性测试完成后,你进行缺陷分析了么?
- BC(转)[js]js计算两个时间相差天数
- 如何发现一个有价值的 GameFi?
- 居民用水问题
- AI+小核酸药物|Eleven完成2200万美元种子轮融资
- 【Word】Word公式导出PDF后出现井号括号#()错误
- [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?
- 主库预警日志报错ORA-00270
猜你喜欢

KingbaseES V8 GIS数据迁移方案(2. Kingbase GIS能力介绍)

Getting Started with Kubernetes Networking

ExcelPatternTool: Excel表格-数据库互导工具

LiveVideoStackCon 2022 Shanghai Station opens tomorrow!

tcp中的三次握手与四次挥手

Use of pytorch: Convolutional Neural Network Module

Countdown to 1 day!From August 2nd to 4th, I will talk with you about open source and employment!

数仓4.0(三)------数据仓库系统

4. PCIe 接口时序

【Word】Word公式导出PDF后出现井号括号#()错误
随机推荐
[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?
为什么他们选择和AI恋爱?
1349. 参加考试的最大学生数 状态压缩
行业现状?互联网公司为什么宁愿花20k招人,也不愿涨薪留住老员工~
torch.autograd.grad finds the second derivative
GCC: paths to header and library files
OPENWIFI实践1:下载并编译SDRPi的HDL源码
oracle create tablespace
Knowledge Points for Network Planning Designers' Morning Questions in November 2021 (Part 1)
Gartner Hype Cycle:超融合技术将在2年内到达“生产力成熟期”
5. PCIe official example
深度学习原理学习小结 - Self-Attention/Transformer
接口自动化测试框架postman tests常用方法
XMjs跨域问题解决
MySQL3
LiveVideoStackCon 2022 Shanghai Station opens tomorrow!
主库预警日志报错ORA-00270
第十一章 开关级建模
Method Overriding and Object Class
day14--postman接口测试