当前位置:网站首页>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 .
边栏推荐
- Community article | mosn building subset optimization ideas sharing
- 推荐几个AI智能平台
- (pytorch进阶之路二)word embedding 和 position embedding
- HMS Core新闻行业解决方案:让技术加上人文的温度
- Recommend several AI Intelligent Platforms
- 对领域驱动设计DDD理解
- Scala语言学习-04-函数作为参数传入函数-函数作为返回值
- Is SQL analysis query unavailable in the basic version?
- 小白操作Win10扩充C盘(把D盘内存分给C盘)亲测多次有效
- C # implements insertion sorting
猜你喜欢

Bridging the gap between open source databases and database services

Research on ICT: domestic databases focus on the ICT market, and Huawei Gauss is expected to become the strongest

Self inspection is recommended! The transaction caused by MySQL driver bug is not rolled back. Maybe you are facing this risk!

Cve-2022-0847 (privilege lifting kernel vulnerability)

Sdvo:ldso+ semantics, direct French Slam (RAL 2022)

【题目精刷】2023禾赛-FPGA

Meet webassembly again

Discover the number of media new users can insert

Promouvoir l'adaptation compatible et permettre le développement collaboratif du Service Express adaptatif gbase en mai

推荐几个AI智能平台
随机推荐
Yilian technology rushes to Shenzhen Stock Exchange: annual revenue of RMB 1.4 billion, 65% of which comes from Ningde times
壹连科技冲刺深交所:年营收14亿 65%收入来自宁德时代
pymssql模块使用指南
(pytorch进阶之路二)word embedding 和 position embedding
The MIHA tour club in June is hot! 500+ posts, more than HC, just this summer (with internal promotion method)
The bank card identification function of Huawei machine learning service enables bank card identification and binding with one click
Ask if you want to get the start of sqlserver_ Is there a good way for LSN?
Navicat Premium 连接Oracle 数据库(图文教程)
百行代码实现基于Redis的可靠延迟队列
Be an we media video blogger, and share the necessary 32 material websites
[single chip microcomputer] [make buzzer sound] know the buzzer and let it make the sound you want
How safe is the new bond
How MySQL modifies the storage engine to InnoDB
洛谷P2466 [SDOI2008] Sue 的小球 题解
使用 zipfile、openpyxl、flask 批量导出excel zip
Ultimate efficiency is the foundation for the cloud native database tdsql-c to settle down
宏源期货开户安全么?宏源期货公司可以降低手续费?
Meet webassembly again
Applet development - Custom expiration cache
OOP 多重收纳(类模板)