Detecting path to shared object

This is a discussion on Detecting path to shared object within the Linux Programming forums, part of the Platform Specific Boards category; Hi, I'm running a process that already loaded mysharedobject.so. I'd like to know in a C program, where was this ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    /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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21