linux c/c++ dll readlink读取进程的程序名与路径
readlink 用于读取本进程的程序名
eadlink()会将参数path的符号链接内容存储到参数buf所指的内存空间
头文件: #include <unistd.h>
定义函数:ssize_t readlink(const char path, char buf, size_t bufsiz);
readlink("/proc/self/exe", exepath, sizeof(exepath));
此技巧可以读取本进程的程序名。
示例:
#define MAX_PATH_LEN 256
string get_process_path()
{
char process_path[MAX_PATH_LEN]={0};
int n = 0;
string strret = "";
memset(process_path, 0x00, MAX_PATH_LEN);
n = readlink("/proc/self/exe", process_path, MAX_PATH_LEN);
if (n != -1)
{
strret.append(process_path, n);
}
else
{
return strret;
}
return strret;
}
本文链接地址:https://const.net.cn/388.html