To get the path of current executable, we have used the following code:
char result[PATH_MAX + 1];
ssize_t count = readlink("/proc/self/exe", result, PATH_MAX);
if (count == -1)
return false;
result[count] = 0;
In addition to using readlink
, I think another probable way is to use fexecve
int fd = open("/proc/self/exe", O_RDONLY);
fexecve(fd, argv, envp);
But I think fexecve
only return the error information if there is an error. Is there any way to receive the path from executing /proc/self/exe
?