获取可执行文件路径

char link[1024], exe_path[1024];
sprintf(link, "/proc/%d/exe", getpid());
readlink(link, exe_path, sizeof(exe_path));

std::string path = exe_path;
path = path.substr(0, path.find_last_of('/'));

pid_t getpid(void): 取得目前进程的进程识别码;

int readlink(const char * path ,char * buf,size_t bufsiz): 将参数path的符号连接内容存到参数buf所指的内存空间;

你可能感兴趣的:(linux)