Skip to main content
add C code
Source Link
meuh
  • 54.7k
  • 2
  • 70
  • 138

For Linux you can read and search through pseudo file /proc/<pid>/maps, where <pid> would be self from a program looking at itself. It has lines for each memory mapped item, which should include each shared library, eg

7f63c2c23000-7f63c2dd0000 r-xp 00000000 08:01 136321 /usr/lib64/libc-2.26.so 

See man proc for details.


There is also a C api for a program to walk through the list of shared objects it is using. See man dl_iterate_phdr. It provides an example of its use. For your use case it is as simple as this:

#define _GNU_SOURCE #include <link.h> #include <stdlib.h> #include <stdio.h> static int callback(struct dl_phdr_info *info, size_t size, void *data){ if(info->dlpi_name[0]!='\0')printf("%s\n", info->dlpi_name); return 0; } int main(int argc, char *argv[]) { dl_iterate_phdr(callback, NULL); exit(EXIT_SUCCESS); } 

For Linux you can read and search through pseudo file /proc/<pid>/maps, where <pid> would be self from a program looking at itself. It has lines for each memory mapped item, which should include each shared library, eg

7f63c2c23000-7f63c2dd0000 r-xp 00000000 08:01 136321 /usr/lib64/libc-2.26.so 

See man proc for details.

For Linux you can read and search through pseudo file /proc/<pid>/maps, where <pid> would be self from a program looking at itself. It has lines for each memory mapped item, which should include each shared library, eg

7f63c2c23000-7f63c2dd0000 r-xp 00000000 08:01 136321 /usr/lib64/libc-2.26.so 

See man proc for details.


There is also a C api for a program to walk through the list of shared objects it is using. See man dl_iterate_phdr. It provides an example of its use. For your use case it is as simple as this:

#define _GNU_SOURCE #include <link.h> #include <stdlib.h> #include <stdio.h> static int callback(struct dl_phdr_info *info, size_t size, void *data){ if(info->dlpi_name[0]!='\0')printf("%s\n", info->dlpi_name); return 0; } int main(int argc, char *argv[]) { dl_iterate_phdr(callback, NULL); exit(EXIT_SUCCESS); } 
Source Link
meuh
  • 54.7k
  • 2
  • 70
  • 138

For Linux you can read and search through pseudo file /proc/<pid>/maps, where <pid> would be self from a program looking at itself. It has lines for each memory mapped item, which should include each shared library, eg

7f63c2c23000-7f63c2dd0000 r-xp 00000000 08:01 136321 /usr/lib64/libc-2.26.so 

See man proc for details.