当前位置:网站首页>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.
边栏推荐
- Activity Recommendation | Kuaishou StreamLake Brand Launch Conference, witness together on August 10!
- 仅3w报价B站up主竟带来1200w播放!品牌高性价比B站投放标杆!
- 1349. 参加考试的最大学生数 状态压缩
- ORA-00257
- Kubernetes 网络入门
- 深度学习:使用nanodet训练自己制作的数据集并测试模型,通俗易懂,适合小白
- IJCAI2022 | DictBert:采用对比学习的字典描述知识增强的预训练语言模型
- 数仓4.0(三)------数据仓库系统
- ORA-00604 ORA-02429
- 原生js实现多选框全部选中和取消效果
猜你喜欢
如何发现一个有价值的 GameFi?
动态规划/背包问题总结/小结——01背包、完全背包
测试工作这么难找吗?今年32,失业2个月,大龄测试工程师接下来该拿什么养家?
【TA-霜狼_may-《百人计划》】图形4.3 实时阴影介绍
1349. 参加考试的最大学生数 状态压缩
蓝牙Mesh系统开发四 ble mesh网关节点管理
Binary tree [full solution] (C language)
超越YOLO5-Face | YOLO-FaceV2正式开源Trick+学术点拉满
IJCAI2022 | DictBert:采用对比学习的字典描述知识增强的预训练语言模型
【FreeRTOS】FreeRTOS与stm32内置堆栈的占用情况
随机推荐
Use of pytorch: Convolutional Neural Network Module
Inter-process communication and inter-thread communication
The principle of NMS and its code realization
测试工作这么难找吗?今年32,失业2个月,大龄测试工程师接下来该拿什么养家?
软件测试技术之最有效的七大性能测试技术
C# const readonly static 关键字区别
Interview summary: Why do interviewers in large factories always ask about the underlying principles of Framework?
Gartner Hype Cycle:超融合技术将在2年内到达“生产力成熟期”
多线程涉及的其它知识(死锁(等待唤醒机制),内存可见性问题以及定时器)
硬实力和软实力,哪个对测试人来说更重要?
面试汇总:为何大厂面试官总问 Framework 的底层原理?
ORA-01105 ORA-03175
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?
[Redis] Redis installation under Linux
迅睿cms网站搬迁换了服务器后网站不能正常显示
How DHCP works
活动推荐 | 快手StreamLake品牌发布会,8月10日一起见证!
Methods commonly used interface automation test framework postman tests
Activity Recommendation | Kuaishou StreamLake Brand Launch Conference, witness together on August 10!
【FreeRTOS】FreeRTOS与stm32内置堆栈的占用情况