I want to load a shared object to certain processes, there are certain conditions that are required

  • loading to only specific processes and not all of them
  • it has to be done before the process code starts executing
  • the processes are not mine

What are the available ways to support this functionality on Linux?

Can it be accomplished with "/etc/ld.so.preload" or "LD_PRELOAD=/my/lib.so"? Is a kernel module needed for this?

Any help would be appreciated


1 Answer 1


The code you can use is something like:

LD_PRELOAD=/my/lib.so /path/to/binary

If this library is required for binary you can use also:

LD_LIBRARY_PATH=/my:$LD_LIBRARY_PATH /path/to/binary

and the binary will search for this library in path /my before searching in standard paths

  • thanks @Romeo Nivov. can it be used when I'm not the one who executes the target processes? I couldn't verify that in the Linux manual for LD_*
    – ALsec
    Aug 30, 2022 at 12:54
  • What do you mean by " I'm not the one who executes the target processes"? You can use this with sudo, in init scripts, etc. Aug 30, 2022 at 13:01
  • I mean for processes created by others (e.g. the OS, other exes), not by my scripts or me as a user with "sudo"...
    – ALsec
    Aug 30, 2022 at 13:06
  • if they execute the command on this way (as shown above) they will have it. If you want to force everyone on the server on every program to have this you can use /etc/ld.so.preload Aug 30, 2022 at 13:09
  • I want it only for selected programs and not all of them (the list is dynamic and managed elsewhere) and automatic so I won't have to manually force "LD_*" on users/programs. thanks!
    – ALsec
    Aug 30, 2022 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.