how is a shared library file called by two different processes in Linux?

前端 未结 2 717
不知归路
不知归路 2020-12-23 19:22

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?

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-23 20:01

    The code for the shared library is copied (or more accurately, mapped) into memory by the operating system.

    Then the OS gives each of the processes access to that one copy in memory.

    It's possible that each of the processes will "see" the copy as being at a different memory address than the other. This is resolved by the CPU's memory management unit.

    It can get more complicated than this, but that's basically how things work in Linux and other Unix-related operating systems like Mac OS X.

提交回复
热议问题