I'm looking for a alternative method to reading the /proc/PID/exe symbolic link in which to obtain the full path of a process in Android/Linux.
The reason being is that on Android, /proc/PID/exe for any process other than your own or 'self' seem to have restricted (permission denied) access.
I have looked into the following as well - they are readable, but don't seem to work:
- /proc/PID/cmdline: Rarely contains the full path
- /proc/PID/stat: Contains only the executable name (no path)
Failing code due to permission denied:
#include <unistd.h>
// ...
char buf[2048];
// "/proc/1234/exe" is of course replaced with a proper PID
ssizet_t len = readlink("/proc/1234/exe", buf, sizeof(buf) - 1);
if(-1 != len) {
buf[len] = '\0';
// buf should contain full path
} else {
// this path always reached for PID's other than my own or
// /proc/self/exe
}
There has to be a alternative method? In Windows, there is of course GetModuleFileNameEx, QueryFullProcessImageName(), etc.