Modify program behavior with LD_PRELOAD
Change Course

© Lead Image © Elnur Amikishiyev, 123RF.com
A little C code and the LD_PRELOAD variable let you customize library functions to modify program behavior.
Perhaps you want to know the files a program opens or deletes and the network connections it establishes. With a simple hack, standard functions such as opening files or listening on a TCP port can be replaced with DIY versions that not only log what the application does but can even change their behavior if desired. The key to these possibilities is the LD_PRELOAD
variable, which affects the Linux program loader.
When you start a program, the Linux kernel creates a new process and loads the executable into its memory space, but that is usually not all that happens. Programs typically use libraries that are added dynamically. You can find out which libraries an application loads using the ldd
command (Figure 1).

[...]
Buy this article as PDF
(incl. VAT)