I'd like to programmatically get a list of the shared libraries linked by my binary on Linux and Solaris. Right now I shell out to pmap (I can't use ldd
on the binary because it won't include dlopen'd libraries, and I can't use pldd
because it's Solaris only):
std::ostringstream cmd;
cmd << "/usr/bin/pmap " << getpid() << " | awk '{ print $NF }' | grep '\\.so' | sort -u";
FILE* p = popen(cmd.str().c_str(), "r");
This is a bit hackish but it works on both Solaris and Linux (the pmap output is slightly different but the desired info is always in the last column). Is there a way to get the same information without shelling out? That works on both platforms? I assume the /proc/$PID
files are formatted differently between them but I don't know where the headers for helping parse those are usually located (if there's a common location at all?).