当前位置:网站首页>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 .
边栏推荐
- Wallys/DR7915-wifi6-MT7915-MT7975-2T2R-support-OpenWRT-802.11AX-supporting-MiniPCIe
- Rosbag use command
- Wechat applet avatar pendant production
- 架构师之路,从「存储选型」起步
- Binary search (integer binary)
- 数字人民币可以买理财产品了!建行APP在试点地区上线服务专区,实测体验如何?
- Cross border integration, creativity and innovation to help improve the influence of cultural tourism night tour
- Navicat Premium 连接Oracle 数据库(图文教程)
- Quickly play ci/cd graphical choreography
- TDengine 连接器上线 Google Data Studio 应用商店
猜你喜欢

MongoDB在腾讯零售优码中的应用

Promoting compatibility and adaptation, enabling coordinated development of gbase may adaptation Express

84.(cesium篇)cesium模型在地形上运动

HMS core news industry solution: let technology add humanistic temperature

【题目精刷】2023禾赛-FPGA

推进兼容适配,使能协同发展 GBase 5月适配速递

Community article | mosn building subset optimization ideas sharing

“软件定义世界,开源共筑未来” 2022开放原子全球开源峰会7月底即将开启

CVE-2022-0847(提权内核漏洞)

Tdengine connector goes online Google Data Studio store
随机推荐
【LeetCode】9、回文数
社区文章|MOSN 构建 Subset 优化思路分享
得物App数据模拟平台的探索和实践
建议自查!MySQL驱动Bug引发的事务不回滚问题,也许你正面临该风险!
B树和B+树
GBASE现身说 “库” 北京金融科技产业联盟创新应用专委会专题培训
【题目精刷】2023禾赛-FPGA
Bridging the gap between open source databases and database services
『忘了再学』Shell流程控制 — 38、while循环和until循环介绍
ORB_VI思想框架
C language learning -18-makefile file writing examples and how to generate and call dynamic libraries
大佬们 2.2.1cdc 监控sqlsever 只能拿到全量的数据 后期增量的数据拿不到 咋回事啊
大佬们好,初次使用MySQL cdc 报错
#进程地址空间
Scala语言学习-05-递归和尾递归效率对比
程序替换函数
C# 实现插入排序
How to use the concat() function of MySQL
“软件定义世界,开源共筑未来” 2022开放原子全球开源峰会7月底即将开启
类似attention nlp