当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
ORA-01105 ORA-03175
ExcelPatternTool: Excel表格-数据库互导工具
超越YOLO5-Face | YOLO-FaceV2正式开源Trick+学术点拉满
金仓数据库 KingbaseES V8 GIS数据迁移方案(3. 基于ArcGIS平台的数据迁移到KES)
LiveVideoStackCon 2022 Shanghai Station opens tomorrow!
MySQL学习
ora-00604 ora-02429
Pytorch usage and tricks
Creative code confession
Why is this problem reported when installing oracle11
Software Testing Interview Questions: What do test cases usually include?
CMS建站流程
How DHCP works
A new technical director, who calls DDD a senior, is convinced
缺陷检测(图像处理部分)
4. PCIe 接口时序
【Endnote】Word插入自定义形式的Endnote文献格式
2021年11月网络规划设计师上午题知识点(上)
【PyQT5 绑定函数的传参】
Pytorch使用和技巧









