Thread: Detecting path to shared object

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    Detecting path to shared object

    Hi,

    I'm running a process that already loaded mysharedobject.so. I'd like to know in a C program, where was this object loaded from.
    In a shell script I would probably do something like
    cat /proc/PID of the process/maps | grep mysharedobject.so

    How does one do that?

    Thanks,
    fb0

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    lsof perhaps?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    3
    Quote Originally Posted by Salem View Post
    lsof perhaps?
    I'm interested in calling a C function, rather than running an application, and the purpose is to find out where a certain library is loaded from.
    This is what "pldd" utility under Solaris does.

    lsof is a utility, and isn't doing what I need.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    /proc/ is the ultimate source of this information. So open /proc/PID/maps and parse it out.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User
    Join Date
    Apr 2011
    Posts
    3
    Quote Originally Posted by brewbuck View Post
    /proc/ is the ultimate source of this information. So open /proc/PID/maps and parse it out.
    Yes, but this is what I wanted to avoid. I still hope there is a more elegant solution.

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by dev.fb0 View Post
    Yes, but this is what I wanted to avoid. I still hope there is a more elegant solution.
    There is not. All programs which obtain this information do so by reading /proc/.

    The dynamic linker itself knows which file was loaded, but there is no interface provided for you to query that information.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Telling a shared_ptr not to delete object?
    By TriKri in forum C++ Programming
    Replies: 5
    Last Post: 08-16-2008, 04:26 AM
  2. Replies: 2
    Last Post: 05-21-2008, 10:40 PM
  3. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  4. Managing shared memory lookups
    By clancyPC in forum Linux Programming
    Replies: 0
    Last Post: 10-08-2003, 04:44 AM

Tags for this Thread