完整源码
#include <sys/statfs.h>
#include <string>
#include <iostream>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
/// get executable path
std::string get_cur_executable_path_()
{
char *p = NULL;
const int len = 256;
/// to keep the absolute path of executable's path
char arr_tmp[len] = {0};
int n = readlink("/proc/self/exe", arr_tmp, len);
if (NULL != (p = strrchr(arr_tmp,'/')))
*p = '\0';
else
{
printf("wrong process path");
std::string("");
}
return std::string(arr_tmp);
}
int main(int argc, char* argv[], char *env[])
{
/// 读取executable所在绝对路径
std::string exec_str