Julio Guerra
Julio Guerra

Reputation: 5661

LD_LIBRARY_PATH side effects

I am having strange side effects on changing LD_LIBRARY_PATH.

When I append a path containing a library, e.g. :

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/my_path/lib

Then, everything becomes unbelievably slow. For example, a simple ls can be 10 seconds long.

ldd output is exactly the same before and after the LD_LIBRARY_PATH change and I tried to debug the execution of the slow ls with strace : I get the exact same execution in both cases. The execution does not even get stuck during the execution of ls (since strace does not output anything during the 10-second lag and then suddenly perfectly executes ls). So I thought it could come from my shell, but this is the same, running strace on my bash and executing ls in both cases gives me the same strace output : the shell executes ls and wait for the end of its execution (the last strace output before the lag strace is waitpid(...)). So I guess something wrong happens between the the launch of ls and its execution, like if it was a kernel-level issue. It really acts like if a sleep was made on ls (0 cpu usage).

During the lag, my CPU and network activity are perfectly normal...

Note that the library in the new LD path does not conflict with any "standard library", so it does not disturb ls in my example.

So I am interesting in deeper explanations about LD_LIBRARY_PATH side effects or how to deeply debug my example.

Upvotes: 7

Views: 1766

Answers (2)

Danduk82
Danduk82

Reputation: 839

This post is quit old, so I don't know if you find already a solution. Anyway, I don't know if this may help, but in most modern GNU/Linux systems, the use of LD_LIBRARY_PATH is deprecated and discouraged.

Therefore I have a couple of suggestions:

  1. if you want to continue using it, try first by pre-pending instead of appending your library path to the LD_LIBRARY_PATH. This should help if there is something that takes long time to scan the path in previous library directories.

  2. Use LDCONFIG system, which is the (new) proper way of using LD directories nowadays. You simply have to add the path to your library in /etc/ld.so.conf file, or better, add a file in /etc/ld.so.conf.d/ which contains the path to your library (it will be sourced if there is an include directive in /etc/ld.so.conf, which is usually the case by default). Then run sudo ldconfig to update the system LD search path.

I hope this help. Cheers

Upvotes: 3

k107
k107

Reputation: 16440

I'm not sure what else is on your LD_LIBRARY_PATH or library you are trying to add or what program you are running, but you are probably better off writing a wrapper script to change LD_LIBRARY_PATH just for the program that needs the extra library so that your system functions like ls aren't affected.

#!/bin/bash
export LD_LIBRARY_PATH=/my_path/lib
program_name

Create file and chmod +x wrapper_name

Upvotes: 0

Related Questions