FIX: [STUDIO-2289] impl processname on linux
Change-Id: I0acb5e002b5c945bb8ca6272ad95d602fde17cfb
This commit is contained in:
parent
0f152c635c
commit
670114c1b3
1 changed files with 11 additions and 1 deletions
|
@ -37,6 +37,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/sendfile.h>
|
#include <sys/sendfile.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1150,7 +1151,16 @@ std::string get_process_name(int pid)
|
||||||
while (auto q = strchr(p + 1, '/')) p = q;
|
while (auto q = strchr(p + 1, '/')) p = q;
|
||||||
return p;
|
return p;
|
||||||
#else
|
#else
|
||||||
return {};
|
char pathbuf[512] = {0};
|
||||||
|
char proc_path[32] = "/proc/self/exe";
|
||||||
|
if (pid != 0) { snprintf(proc_path, sizeof(proc_path), "/proc/%d/exe", pid); }
|
||||||
|
if (readlink(proc_path, pathbuf, sizeof(pathbuf)) < 0) {
|
||||||
|
perror(NULL);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
char *p = pathbuf;
|
||||||
|
while (auto q = strchr(p + 1, '/')) p = q;
|
||||||
|
return p;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue