title: Get a list of all shared libraries that a running service is using in Ubuntu
body: <p>Some solutions I found for the above problem are : (let's take an example of a running service, say <code>/usr/sbin/acpid</code> and say the pid of the process is 1234)</p>
  
  <ol>
  <li><p><strong>ldd /usr/sbin/acpid</strong><br>Output:</p>
  
  <blockquote>
    <p>linux-vdso.so.1 =>  (0x00007ffe5eb7a000)<br>
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa0b1a48000)<br>
    /lib64/ld-linux-x86-64.so.2 (0x000055a297a76000)<br></p>
  </blockquote></li>
  <li><p><strong>sudo objdump -p /usr/sbin/acpid | grep NEEDED</strong><br>Output:</p>
  
  <blockquote>
    <p>NEEDED               libc.so.6</p>
  </blockquote></li>
  <li><strong>sudo pmap 1234</strong><br>Output:
  
  <blockquote>
    <p>1234:   /usr/sbin/acpid<br>
    0000000000400000     44K r-x-- acpid<br>
    000000000060a000      4K r---- acpid<br>
    000000000060b000      4K rw--- acpid<br>
    000000000060c000      4K rw---   [ anon ]<br>
    00000000020ce000    132K rw---   [ anon ]<br>
    00007f0ac06c7000   1788K r-x-- libc-2.23.so<br>
    00007f0ac0886000   2048K ----- libc-2.23.so<br>
    00007f0ac0a86000     16K r---- libc-2.23.so<br>
    00007f0ac0a8a000      8K rw--- libc-2.23.so<br>
    00007f0ac0a8c000     16K rw---   [ anon ]<br>
    00007f0ac0a90000    152K r-x-- ld-2.23.so<br>
    00007f0ac0caa000     12K rw---   [ anon ]<br>
    00007f0ac0cb3000      8K rw---   [ anon ]<br>
    00007f0ac0cb5000      4K r---- ld-2.23.so<br>
    00007f0ac0cb6000      4K rw--- ld-2.23.so<br>
    00007f0ac0cb7000      4K rw---   [ anon ]<br>
    00007ffcacbda000    132K rw---   [ stack ]<br>
    00007ffcacbfb000      8K r----   [ anon ]<br>
    00007ffcacbfd000      8K r-x--   [ anon ]<br>
    ffffffffff600000      4K r-x--   [ anon ]<br>
    total             4400K<br></p>
  </blockquote></li>
  <li><strong>readelf -d /usr/sbin/acpid | grep NEEDED</strong><br>Output:
  
  <blockquote>
    <p>0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]</p>
  </blockquote></li>
  </ol>
  
  <p>Also in the process, I learned about what exactly are shared libraries and how are they handled in Linux on a broad level. </p>
  
  <p>Now here are the things that I need help with:</p>
  
  <ol>
  <li>If we look at the output of each of the solutions above, <em>libc.so.6</em> is present in the output of solutions 1, 2 and 4 but not in 3. Also the output of solution 1 above reports <em>inux-vdso.so.1</em> and <em>/lib64/ld-linux-x86-64.so.2</em> as well which no other solution reports. So which of these solutions should be taken as the accurate one.</li>
  <li>As per my understanding, shared libraries are loaded into the memory by the loader at runtime. Also, <em>on demand</em> a process can load any more shared libraries when ever needed. Am I right or wrong here ? In case right, the shared libraries being used by any given process could always be dynamic. So, if I really need to know the shared libraries being used by a process, will I need to poll the process all the time to figure this out ? (Am sure there is much better /elegant solution to this)</li>
  <li>Solution 1, the <em>ldd</em> approach, is something I would want to avoid because of the inherent security risk it has (depending on the version of the ldd being used) of starting an executable itself to figure out it's shared libraries. </li>
  </ol>
  
  <p>So what is the best approach to figure out the shared libraries being used by a process?</p>