Hi Shivali, I found some relevant information on the following link after googling about this: http://groups.google.co.in/group/comp.os.linux.development.system/browse_thread/thread/bf8d761cc14c317a/7bd81eac9f5fe952?lnk=st&q=ld.so+%2B+how+it+works&rnum=72&hl=en#7bd81eac9f5fe952 Basically, ld.so calls mmap system call to memory map the shared library file. Now if one process had already mapped the library, when another process wants to use the same library, the mmap syscall (which is called by ld.so for the second process) takes care of determing that the shared library file had already been mapped earlier and thus to not load it again. Hope this clears some doubt. This is what I understood. Any corrections from anyone are more than welcome. Rgds, Sumit On 08/04/06, shivaligupta <shivaligupta308@xxxxxxxxx> wrote: > Hi Hareesh! > > Thanks a lot for the help. But my doubt is not what u explained me but > that how two diff processes uses the same shared library? > > Regards > Shivali > > Hareesh Nagarajan wrote: > > > On 4/7/06, *shivaligupta* <shivaligupta308@xxxxxxxxx > > <mailto:shivaligupta308@xxxxxxxxx>> wrote: > > > > Where in memory is shared library loaded? > > i guess it should be in the process virtual address space only but if > > that is the case how another process which wants to use the same > > library > > comes to know that the library has already been loaded and how is it > > able to use that? > > > > > > > > Read the following link: > > http://www.tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html > > > > But, to help you out a little, check this out: > > > > $ cat x.c > > #include <stdio.h> > > > > main() > > { > > printf("hit any key..."); > > getchar(); > > } > > > > $ gcc x.c -ox > > $ ./x > > > > $ readelf -a x | grep getchar > > 0804960c 00000107 R_386_JUMP_SLOT 00000000 getchar > > 1: 00000000 221 FUNC GLOBAL DEFAULT UND getchar@xxxxxxxxx (2) > > 82: 00000000 221 FUNC GLOBAL DEFAULT UND getchar@@GLIBC_2.0 > > > > $ readelf -a x | grep printf > > 08049614 00000307 R_386_JUMP_SLOT 00000000 printf > > 3: 00000000 57 FUNC GLOBAL DEFAULT UND printf@xxxxxxxxx (2) > > 97: 00000000 57 FUNC GLOBAL DEFAULT UND printf@@GLIBC_2.0 > > > > The addresses of printf and getchar are undefined and will be resolved > > at run time. > > > > $readelf -a ./x > > > > [snip] > > 0x00000001 (NEEDED) Shared library: [libc.so.6] > > [snip] > > > > With this hint, ld figures out it needs to load the shared library. > > Let us run program ./x in one terminal and check its process map from > > another. > > > > hareesh@salty:~$ pmap `pgrep ./x` > > 11680: ./x > > 08048000 4K r-x-- /x > > 08049000 4K rw--- /x > > 40000000 88K r-x-- /ld-2.3.2.so <http://2.3.2.so> <--- Loader > > 40016000 4K rw--- /ld-2.3.2.so <http://2.3.2.so> > > 40017000 12K rw--- [ anon ] > > 40022000 1192K r-x-- /libc-2.3.2.so <http://2.3.2.so> <--- glibc > > (code section; perhaps) > > 4014c000 36K rw--- /libc-2.3.2.so <http://2.3.2.so> <--- glibc > > (data section; perhaps) > > 40155000 12K rw--- [ anon ] > > bfffe000 8K rw--- [ stack ] > > ffffe000 4K ----- [ anon ] > > total 1364K > > > > -- > > c u > > > > ./hareesh > > > > -- > Kernelnewbies: Help each other learn about the Linux kernel. > Archive: http://mail.nl.linux.org/kernelnewbies/ > FAQ: http://kernelnewbies.org/faq/ > > -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/