How to check currently used libraries from command line ?

Home » Asterisk Users » How to check currently used libraries from command line ?
Asterisk Users 5 Comments

Hi,

I’ve recently upgraded a system from 1.8 to asterisk 10 and also
updated spandsp while doing so.
I wondered what is the safest and easiest way to check from command
line which libraries a running Asterisk system is currently using
(just like “dahdi show version”, for instance).

Though I’m currently asking this for spandsp, this question is on a
more general plan (for example, which ssl library am I currently using
?).

Suggestions ?

Regards

5 thoughts on - How to check currently used libraries from command line ?

  • Hi Olivier,

    I suppose you give “strace” a try.
    It’s a powerful debugging utility, you should be able to find everything
    you are looking for.

    best regards,
    Ruben

    Am 16.01.2012 11:14, schrieb Olivier:

  • 2012/1/16, Anton Kvashenkin :

    Thanks for replying.

    I got this:
    # ldd /usr/sbin/asterisk
    linux-gate.so.1 => (0xb7886000)
    libssl.so.0.9.8 => /usr/lib/i686/cmov/libssl.so.0.9.8 (0xb7834000)
    libcrypto.so.0.9.8 => /usr/lib/i686/cmov/libcrypto.so.0.9.8 (0xb76dc000)
    libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb7595000)
    libxml2.so.2 => /usr/lib/libxml2.so.2 (0xb746b000)
    libsqlite3.so.0 => /usr/lib/libsqlite3.so.0 (0xb73df000)
    libdl.so.2 => /lib/i686/cmov/libdl.so.2 (0xb73db000)
    libpthread.so.0 => /lib/i686/cmov/libpthread.so.0 (0xb73c2000)
    libncurses.so.5 => /lib/libncurses.so.5 (0xb7387000)
    libm.so.6 => /lib/i686/cmov/libm.so.6 (0xb7361000)
    libresolv.so.2 => /lib/i686/cmov/libresolv.so.2 (0xb734d000)
    libz.so.1 => /usr/lib/libz.so.1 (0xb7339000)
    /lib/ld-linux.so.2 (0xb7887000)
    # ldd /usr/lib/libspandsp.so
    linux-gate.so.1 => (0xb77a1000)
    libtiff.so.4 => /usr/lib/libtiff.so.4 (0xb769b000)
    libm.so.6 => /lib/i686/cmov/libm.so.6 (0xb7675000)
    libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb752e000)
    libjpeg.so.62 => /usr/lib/libjpeg.so.62 (0xb750e000)
    libz.so.1 => /usr/lib/libz.so.1 (0xb74fa000)
    /lib/ld-linux.so.2 (0xb77a2000)

    So, with those 2 commands, I couldn’t directly check the link between
    asterisk and spandsp, and check am I’m really using spandsp0.0.6pre18.

  • To find out which libraries a particular binary executable program is linked
    against, you just need to do

    $ ldd /path/to/executable

    You can find the actual path to an executable by typing

    $ which foo

    Replace foo by the name of the executable about which you want information,
    obviously.

    Now, because we usually want the computer to do as much of the hard work for
    us as possible, we can use the $(command) operator — which treats whatever is
    between the brackets as a command, runs it and substitutes its output into the
    command which it was part of — to combine these two commands into one:

    $ ldd $(which foo)

    i.e. it will run “which foo”, and then do “ldd” on whatever output “which foo”
    returned.

    Trivial example below:

    $ ldd $(which ls)
    linux-vdso.so.1 => (0x00007fffa7974000)
    libselinux.so.1 => /lib/libselinux.so.1 (0x00007fdc03188000)
    librt.so.1 => /lib/librt.so.1 (0x00007fdc02f80000)
    libacl.so.1 => /lib/libacl.so.1 (0x00007fdc02d78000)
    libc.so.6 => /lib/libc.so.6 (0x00007fdc02a17000)
    libdl.so.2 => /lib/libdl.so.2 (0x00007fdc02813000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fdc033ce000)
    libpthread.so.0 => /lib/libpthread.so.0 (0x00007fdc025f6000)
    libattr.so.1 => /lib/libattr.so.1 (0x00007fdc023f2000)

    Hmm, that’s a whole lot of libraries just to get a directory listing! Not
    surprisingly, busybox gets away with rather less:

    $ ldd $(which busybox)
    linux-vdso.so.1 => (0x00007fff2b7ff000)
    libm.so.6 => /lib/libm.so.6 (0x00007f04a8217000)
    libc.so.6 => /lib/libc.so.6 (0x00007f04a7eb6000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f04a84c1000)

    Note1: Here we see 16 hex digits after each library name, indicating a 64-bit
    system. On a 32-bit system, we would see only 8 hex digits after each library
    name.

    Note2: Programs that sometimes or always crash, may be missing a library. If
    so, this will be obvious when you run ldd.

  • To see the actual memory map of the process:

    pmap $PID_OF_ASTERISK

    Code is mapped from files, and thus you’ll see the original files.
    You’ll probably need to remove duplicates and such.

    Note that ldd of /usr/sbin/asterisk will not give you libraries of the
    various modules. For that you’ll have to run ldd on the specific
    modules.