当前位置:网站首页>Process address space
Process address space
2022-06-22 15:57:00 【Stock god.】
Scene Introduction
When we learn various languages , You usually hear that the memory is divided into the following areas :
We do an experiment with the following code : At the beginning , We print val The value and address of , Because the child process did not modify the data , So the parent and child processes share a copy of the code , So at first , The values we print are the same . But when cnt==3 when , Subprocess modified g_val Value , So a write time copy is sent , At this point, the parent-child process prints g_val The value and address of should be different . But will the result be what we imagined ?
Found after running results :g_val After modification , The printed values are different , But the address is the same !
Why is the parent-child process g_val The value of is the same , The address is different ? Because the space used by language programs is not physical memory , It's the process address space ! If it is the same physical memory , It is impossible to have the same space , But different values .
Process address space
Processes do not use physical memory directly , Instead, use the process address space , Then map to the physical memory through the page table . When we create a process , In addition to creating pcb, Also create a structure — Process address space variables (mm_struct). The purpose of creating the process address space is to make the process think that it owns the operating system .
So the logic of the process using space is this :
So in the first code , Father son process g_val The address is the same for different values of , Because g_val The address in the process address space of the parent-child process is the same , But the parent-child process g_val The addresses mapped to the physical space must be different .
After understanding what the process address space is , So why do you need a process address space ?
- It is not safe to manipulate physical memory directly because it is not safe . If the program illegally accesses or destroys data , Will seriously threaten computer security . So the process address space is introduced to separate the program from the physical memory , Let the operation of physical memory be left to the operating system .
- Divide the concepts of memory application and memory use in time , Through virtual address space , To mask the process of applying for memory at the bottom , Achieve process read-write memory and OS Perform memory management operations , Separate the software . for example : When we apply 1000 A space of bytes , If you don't use this space immediately ( That is, do not use read-write operations ), This space is not immediately available to you in physical memory . Because if you apply for space , But don't use , Other processes cannot use this space , That's a waste of space . therefore , When we apply for space , Only one will be opened in the process address space “ Virtual space ”, Tell you that this space has been applied for ; When you actually use this space by reading and writing , Will open up this space on the physical memory for you , And write the data to the physical space through the write time copy .
- With an address space ,cpu You can go to a fixed location in the address space to read code and data , Then map through the page table , Find the real code and data ; With address space and page table mapping , When the disk loads data into physical memory , Can be loaded to any location in physical memory , Reduce the pressure of memory management (cpu To read data, just go to a fixed location , Find the data and give it to the operating system , Look through the address space and page table ). If there is no address space ,cpu Read the code and data of each process , You have to go to different physical spaces , increase cpu burden .
边栏推荐
- 迷宫问题(BFS记录路径)
- 信创研究:国产数据库聚焦信创市场,华为Gauss有望成为最强
- ArcGIS JS之 4.23之IIS本地部署与问题解决
- Quick sort_ sort
- Promouvoir l'adaptation compatible et permettre le développement collaboratif du Service Express adaptatif gbase en mai
- "Forget to learn again" shell process control - 38. Introduction to while loop and until loop
- 程序替换函数
- 各位学弟学妹,别再看教材了,时间复杂度看这篇就好了
- [single chip microcomputer] [make buzzer sound] know the buzzer and let it make the sound you want
- 做自媒体视频博主,必备的32个素材网站分享
猜你喜欢

推進兼容適配,使能協同發展 GBase 5月適配速遞

快速玩转CI/CD图形化编排

模板特例化 template<>

多年亿级流量下的高并发经验总结,都毫无保留地写在了这本书中

pymssql模块使用指南

FPGA采集DHT11温湿度

How MySQL modifies a field to not null

#进程地址空间

The IPO of Tian'an technology was terminated: Fosun and Jiuding were shareholders who planned to raise 350million yuan
![[single chip microcomputer] [make buzzer sound] know the buzzer and let it make the sound you want](/img/cb/826b3591bafa62cc71826732eb32ef.png)
[single chip microcomputer] [make buzzer sound] know the buzzer and let it make the sound you want
随机推荐
Hello, big guys. Error reporting when using MySQL CDC for the first time
『忘了再学』Shell流程控制 — 38、while循环和until循环介绍
The summary of high concurrency experience under the billion level traffic for many years is written in this book without reservation
GBASE现身说 “库” 北京金融科技产业联盟创新应用专委会专题培训
华为云HCDEZ专场暨分布式技术峰会:华为云分布式云原生技术与实践之路
Discover the number of media new users can insert
How can ordinary people make 1million yuan a year?
快速排序quick_sort
关于 GIN 的路由树
Mitsubishi manipulator demo program
stack和queue的模拟实现
C语言学习-17-函数作为参数传入函数
C语言学习-18-makefile文件编写例子以及如何生成、调用动态库
三菱机械臂demo程序
Oracle客户端和服务端的区别
推進兼容適配,使能協同發展 GBase 5月適配速遞
Jenkins automatically triggers compilation by checking code submissions
希尔排序的简单理解
多年亿级流量下的高并发经验总结,都毫无保留地写在了这本书中
FPGA collects DHT11 temperature and humidity