static core filesystem path getFilePath pid_t pid if pid return not se

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
static core::filesystem::path getFilePath(pid_t pid) {
if (pid <= 0) {
return "<not set>";
}
char buff[PATH_MAX];
ssize_t len = readlink(fmt::sprintf("/proc/%d/exe", pid).data(), buff, sizeof(buff)-1);
if (len != -1) {
buff[len] = '\0';
return core::filesystem::canonical(core::filesystem::absolute(buff));
}
return "<" + std::to_string(pid) + ">";
}