While working on Unix and Linux . we need to create a patch or a local change . this patch change is compiled and built into shared object .
when we run our services , however there is always doubt , whether code change has been really picked up by running service . Many of times , we resort to put printfs(debugs ) into the code and run again .
Our shared object ,could be lying in multiple paths ,due to which it is possible that , exact location from which shared object is loaded may not be known.
One possible solution
In Linux , Unix , there is environment variable LD_LIBRARY_PATH which governs the order in which shared object is loaded .
We can check these paths individually and determine where the shared object is present .If shared object is present in
In such case , shared object would be picked up from /users/tanmay/tests.
There is alternative solution to verify whether local change has been picked up or not ..
In HP Unix and Linux there is command called as pmap . when pmap is run against running process , it will give list of shared objects loaded and path from which shard object is loaded.
Following would be the illustration of pmap command in linux.
My add function has mistake . add function instead of doing add , is doing subtract. However my shared object mylib.so are present in multiple paths.
int add(int num1 , int num2 )
return num1 — num2 ;
int multiply(int num1 , int num2 )
return num1 * num2 ;
int div(int num1 , int num2 )
return num1 + num2 ;
int sub(int num1 , int num2 )
return num1 + num2 ;
lib1.c and lib2.c are built into library => mylib.so
/usr/bin/g++ -shared -Wl,-Bsymbolic -o mylib.so -s -m64 lib1.o lib2.o -L/usr/lib64 -lc -lncurses -ldl -fPIC
myexe.c — is the main program which is doing to use add function defined in lib1.c
printf(“Sleeping for 15 secs\n”);
x = add(10,5);
printf(“Post sleep result is [%d]\n”,x);
myexe is created , linking mylib.so , we will use g++ linker
/usr/bin/g++ -o myexe -m64 -s myexe.o mylib.so
when you run myexe — we can run pmap command on the pid of the exe ,so as to see .from which path exe and shared object is loaded .
pmap command takes the pid as argument . pmap commad clearly shows the path from which shared library is loaded.
>>>pmap 13632 | grep mylib
00007fac56ea4000 4K r-x — /users/e463566/example/mylib.so
00007fac56ea5000 2044K — — — /users/e463566/example/mylib.so
00007fac570a4000 4K rw — — /users/e463566/example/mylib.so