Linux中两个不同的进程如何调用共享库文件? [英] how is a shared library file called by two different processes in Linux?

查看:410
本文介绍了Linux中两个不同的进程如何调用共享库文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux中, 我有一个共享库文件foo.so 当我执行2个不同的进程p1,p2时,它们都使用foo.so. 这个foo.so是否会被这两个进程重叠?

In Linux, I have a shared library file called foo.so When I execute 2 different process p1, p2 that both use foo.so. Does this foo.so get overlapped by those 2 process?

推荐答案

在基于Unix的系统(包括Linux)上,

On Unix-based systems (includes Linux), the code segment (.text) may be shared among multiple processes because it's immutable. Is this overlapping you mention?

基本上,每个包含静态数据(例如全局变量)的共享库都具有

Basically, each shared library that contains static data (such as global variables) has a Global Offset Table (GOT). On shared libraries, all references to static data (think of global vars) occur via GOT (they're indirect). So even if the code segment is shared among multiple processes, each process has its exclusive mapping of other segments of the shared library, including the respective GOT, whose entries are relocated accordingly.

简而言之,仅代码在进程之间共享,而不是数据.但是,我认为常量可能是一个例外,具体取决于编译标志.

In short, only code is shared among processes, not data. However, I think constants may be an exception depending on compilation flags.

我还推荐以下书籍的第10章,<动态>动态链接和加载:链接器和加载程序.

I also recommend chapter 10, Dynamic Linking and Loading, from the following book: Linkers and Loaders.

这篇关于Linux中两个不同的进程如何调用共享库文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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