I would like to programmatically get a list of shared libraries linked by my binary on Linux and Solaris. Right now I am posting on pmap (I cannot use lddbinary because it will not include dlopen'd libraries, and I cannot use plddbecause it is only Solaris):
std::ostringstream cmd;
cmd << "/usr/bin/pmap " << getpid() << " | awk '{ print $NF }' | grep '\\.so' | sort -u";
FILE* p = popen(cmd.str().c_str(), "r");
It's a bit hacky, but it works on both Solaris and Linux (the pmap output is slightly different, but the desired information is always in the last column). Is there a way to get the same information without shelling? Does it work on both platforms? I assume that the files are /proc/$PIDformatted differently between them, but I donβt know where the headers are usually located in order to help with their parsing (if there is a common place at all?).
source
share