通过readlink的方式获取。
bool GetExePath(std::string &path) { std::string exe_path(PATH_MAX, std::string::value_type()); auto exe_path_len = readlink("/proc/self/exe", &exe_path[0], exe_path.size()); if (exe_path_len < 0) { std::cerr << "readlink failed!, exe_path_len < 0"<< std::endl; return false; } else if (static_cast<size_t>(exe_path_len) >= exe_path.size()) { std::cerr << "readlink failed!, exe_path_len >= exe_path.size()"<< std::endl; return false; } exe_path.resize(exe_path_len); auto pos = exe_path.rfind('/'); if (pos == std::string::npos) { std::cerr << "exe_path.rfind fail!, exe_path.rfind = npos"<< std::endl; return false; } path = exe_path.substr(0, pos); return true; }
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。