how to get the path of current exe in addition to using readlink in Linux?

时间:2019-04-17 01:06:36

标签: c++ path

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?

0 个答案:

没有答案