进程内存映射中的文本部分 [英] text section in process memory map

查看:95
本文介绍了进程内存映射中的文本部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,进程内存映射由堆栈,文本,data + bss和堆组成.

Normally, the process memory map consists of stack, text, data+bss and heap.

内存地址独立于文本段以外的其他进程.

The memory address is independent to other processes except text section.

我的问题是关于文本部分的,只有子进程可以共享

My question is about in text section, is there only child process could share

与父进程相同的文本部分?或其他进程也可以共享它.

the same text section with its parent process? or other processes could share it too.

================================================ ======================

======================================================================

@avd:是的,请参阅维基百科

@avd: yes, refer to the wikipedia

http://en.wikipedia.org/wiki/Process_isolation

可以通过虚拟地址空间实现进程隔离,其中虚拟进程A的地址空间与虚拟进程B的地址空间不同-防止虚拟机A写入B."

"Process isolation can be implemented by with virtual address space, where process A's address space is different from process B's address space - preventing A to write into B."

这是我对每个进程都有自己的内存映射的意思.

This is what I mean to each process has its own memory map.

但是,当我阅读OS书籍时,它提到可以共享文本部分.因此,我对此不太清楚,或者我可能误解了本书的那一部分.

However, when I read the OS book, it mentions that the text section could be shared. So I am not very clear with this or probably I misunderstood that part of the book.

================================================ ======================= 额外信息:

====================================================================== Extra information:

http://www.hep.wisc.edu/~pinghc/Process_Memory. htm

如果要同时执行程序的第二个副本,则进程共享文本段.在此设置下,系统将使用指针引用先前加载的文本段,而不是重新加载重复的文本段.如果需要,可以在编译时使用-N选项关闭共享文本(这是使用C/C ++编译器时的默认设置).

Processes share the text segment if a second copy of the program is to be executed concurrently. In this setting, the system references the previously loaded text segment with the pointer rather than reloading a duplicated. If needed, shared text, which is the default when using the C/C++ compiler, can be turned off by using the -N option on the compile time.

推荐答案

每个进程都有自己的虚拟地址.该虚拟地址未与包括子进程在内的任何人共享.但是,这些虚拟地址已由OS内核和MMU转换或换成映射到物理地址.

Every process has it's very own virtual addresses. That virtual address is not shared with anybody including child process. But these virtual addresses are translated or, in other words, mapped to physical addresses by OS kernel and MMU.

问题在于,来自不同地址空间的虚拟地址可以指向相同的物理地址!例如,当进程分叉时,它将获得自己的虚拟地址空间,但是除非此子进程不更改(写)到其内存中,否则它会与父进程共享内存阅读.当子进程将尝试修改某些内存内核时,它将为子进程创建特定页面的单独的自己的副本,并且不再共享(直到子进程自行分叉).这就是所谓的写时复制(CoW).

The thing is that virtual addresses from different address spaces can point to the same physical addresses! For example, when process forked, it gets its own virtual address space, but unless this child process is not changing (writing) to it's memory it shares memory with parent process for reading. When child process will try to modify some memory kernel will create separate own copy of particular page for child process and it will not be shared anymore (until child process forked itself). This is known as Copy on Write (CoW).

所以真正的事实是,可以通过将不同的虚拟页面映射到相同的物理页面(称为框架)来共享文本部分.

So the real thing is that text section could be shared by mapping different virtual pages to the same physical pages (called frames).

这篇关于进程内存映射中的文本部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆