Re: Dynamic linking library

"Michal Nazarewicz" <[email protected]> Thu, 20 Jan 2011 15:50:36 +0100
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <[email protected]>
On Thu, 20 Jan 2011 12:37:25 +0100, ratheesh k <[email protected]>  
wrote:

> Suppose there are two executable elf . say A, B . And these two are
> using  libctest.so.
> When A is executed  libctest.so is loaded into RAM and linear address
> is  correctly mapped.
>
> If we execute program B after A ,  will library will be loaded again ?

When A is executed dynamic loader opens the library and then mmap(2)s it
into virtual address space.

When B is executed, from user space (ie. dynamic loader) point of view the
very same thing happens: dynamic loader opens the library and mmap(2)s it
into virtual address space.

What happens behind the scene, is that when the libctest.so is opened, file
system figures out it's inode and then opens file with given inode number.
The first time this is done, system creates all bunch of structures for
the file, however, the second time, system sees that a file with given  
inode
number is already opened so some data can be shared between the two  
instances.