-   Linux - Newbie (
-   -   Does LD_LIBRARY_PATH variable loads all shared libraries in the directory to ram (

babu198649 06-27-2008 05:31 AM

Does LD_LIBRARY_PATH variable loads all shared libraries in the directory to ram
Assume some 10 shared libraries(*.so files) are present in /usr/local/lib directory.

if i export the path like this

[babu@localhost ~]$ export LD_LIBRARY_PATH=/usr/local/lib:LD_LIBRARY_PATH
does all the 10 shared libraries(assumption) in the directory /usr/local/lib will be loaded to ram.

unSpawn 06-27-2008 06:14 AM

No LD_LIBRARY_PATH does not load libraries into RAM, like any form of PATH it just points to a location on the system. Maybe check the "readahead" service.

tronayne 06-27-2008 06:19 AM

No, they will not be loaded, they will be searched at load time.

When you add (you're adding an additional path to the environment variable LD_LIBRARY_PATH), do it like this:

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib
This appends /usr/local/lib to the existing LD_LIBRARY_PATH; the way you've shown it you have replaced LD_LIBRARY_PATH with /usr/local/lib -- the $ are important!

marozsas 06-27-2008 07:00 AM

To load libs in cache you need to list the path (in this case /usr/local/lib) in /etc/
The cache is what you call "load in ram". In fact it not just pre-loads the libs in memory buffer but it builds a table with entries for all symbols on the so objects, discard duplicates and invalid entries.

Almost all general purpose distros already have /usr/local/lib listed in /etc/ Check yours first.

After changing /etc/ you need to update the cache with the command "ldconfig".
To get a list of libs on the cache, use "ldconfig -p".


babu198649 06-27-2008 08:09 AM

thanks for u r replys

the ldconfig -p says 1243 libs found in cache `/etc/'(then it lists all the files) .Does this means all the 1243 files will be present in ram all the time.

in this link
the doc says
it(ie.shared libraries) must be loaded from disk before the executable will run

so after the executable is terminated does the shared library which is loaded(from the path present in LD_LIBRARY_PATH) will also be unloaded, right? or ,if another application wants the same shared library what does happen.


the $ are important
thanks tronayne.

marozsas 06-27-2008 08:24 AM

No. once on cache it remains there until the cache is rebuilded by another "ldconfig" command.
You can easilly verify this by writing a small C program that use a simple C function on a shared library for your own. - ok, maybe not so easilly ;)
Put your small lib in a distinct folder, like "/usr/local/testlib", put this path in /etc/, re-run "ldconfig", verify it is in cache with ldconfig -p, run your test program, and when it finish, verify your lib still is in the cache.

This is a good exercice and you will learn a lot about linking and shared libs if you do it by yourself.


All times are GMT -5. The time now is 11:31 AM.