当前位置:网站首页>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.
边栏推荐
- 1349. 参加考试的最大学生数 状态压缩
- Software Testing Interview Questions: Qualifying Criteria for Software Acceptance Testing?
- 深度学习训练前快速批量修改数据集中的图片名
- 3. pcie.v 文件
- A new technical director, who calls DDD a senior, is convinced
- The method of freely controlling concurrency in the sync package in GO
- VOC格式数据集转COCO格式数据集
- oracle create user
- 金仓数据库 KingbaseES V8 GIS数据迁移方案(3. 基于ArcGIS平台的数据迁移到KES)
- DHCP的工作过程
猜你喜欢
码率vs.分辨率,哪一个更重要?
Interview summary: Why do interviewers in large factories always ask about the underlying principles of Framework?
DHCP的工作过程
After the staged testing is complete, have you performed defect analysis?
10年测试经验,在35岁的生理年龄面前,一文不值
oracle create tablespace
从一次数据库误操作开始了解MySQL日志【bin log、redo log、undo log】
活动推荐 | 快手StreamLake品牌发布会,8月10日一起见证!
仅3w报价B站up主竟带来1200w播放!品牌高性价比B站投放标杆!
Three handshake and four wave in tcp
随机推荐
Knowledge Points for Network Planning Designers' Morning Questions in November 2021 (Part 1)
OPENWIFI实践1:下载并编译SDRPi的HDL源码
GCC:屏蔽动态库之间的依赖
5. PCIe official example
tcp中的三次握手与四次挥手
GCC:头文件和库文件的路径
测试工作这么难找吗?今年32,失业2个月,大龄测试工程师接下来该拿什么养家?
软件基础的理论
[FreeRTOS] FreeRTOS and stm32 built-in stack occupancy
动态规划/背包问题总结/小结——01背包、完全背包
第09章 性能分析工具的使用【2.索引及调优篇】【MySQL高级】
Lattice PCIe 学习 1
Pytorch usage and tricks
数仓4.0(三)------数据仓库系统
详细全面的postman接口测试实战教程
原生js实现多选框全部选中和取消效果
Binary tree [full solution] (C language)
行业现状?互联网公司为什么宁愿花20k招人,也不愿涨薪留住老员工~
内存取证系列1
深度学习:使用nanodet训练自己制作的数据集并测试模型,通俗易懂,适合小白