加入收藏 | 设为首页 | 会员中心 | 我要投稿 济南站长网 (https://www.0531zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

如何从库中获取地址信息以在所有进程之间共享?

发布时间:2021-01-11 21:06:15 所属栏目:Linux 来源:网络整理
导读:在了解Linux内核第3版中,它说: Shared libraries are especially convenient on systems that provide file memory mapping,because they reduce the amount of main memory requested for executing a program. When the dynamic linker must link a sha

在了解Linux内核第3版中,它说:

Shared libraries are especially convenient on systems that provide file memory mapping,because they reduce the amount of main memory requested for executing a
program. When the dynamic linker must link a shared library to a process,it does not copy the object code,but performs only a memory mapping of the relevant portion of the library file into the process’s address space. This allows the page frames containing the machine code of the library to be shared among all processes that are using the same code. Clearly,sharing is not possible if the program has been linked statically. (page 817)

我对此感兴趣,想要在C中编写一个小程序来验证,给出两个pid作为输入,例如两个gedit进程,然后从页面帧中获取要共享的地址信息.有谁知道怎么做?从那本书中,我认为来自两个或更多gedit进程的bss段和文本段地址是相同的,这是正确的吗? 最佳答案 你的gedit(或其他)的text和bss部分不是具有相同地址的文本和bss部分,而是libc.so共享库的内容 – 以及两个gedit进程使用的所有其他共享库.

正如引用的文本所说,这允许共享库是一个副本,这通常是共享库的主要好处.

bss通常不共享 – 因为这是每个流程数据.在Linux中,运行相同可执行文件的两个进程的文本部分将共享相同的代码.

不幸的是,证明这一点的方法是查看进程内页面的物理映射(进程A中的地址X的页面位于物理地址Y,进程B中的地址X的页面也是物理地址Y),以及据我所知,这并不容易在OS内核内部搞定.

(编辑:济南站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读