linux 获取exe的路径
2013-10-07 14:48
555 查看
使用示例:
int bufsize = 1024; char buffer[bufsize]; readlink("/proc/self/exe", buf, bufsize);
To summarize:
On Unixes with
/procreally
straight and realiable way is to:
readlink("/proc/self/exe", buf, bufsize)(Linux)
readlink("/proc/curproc/file", buf, bufsize)(FreeBSD)
readlink("/proc/self/path/a.out", buf, bufsize)(Solaris)
On Unixes without
/proc(i.e.
if above fails):
If argv[0] starts with "/" (absolute path) this is the path.
Otherwise if argv[0] contains "/" (relative path) append it to cwd (assuming it hasn't been changed yet).
Otherwise search directories in
$PATHfor
executable
argv[0].
Afterwards it may be reasonable to check whether the executable isn't actually a symlink. If it is resolve it relative to the symlink directory.
This step is not necessary in /proc method (at least for Linux). There the proc symlink points directly to executable.
Note that it is up to the calling process to set
argv[0]correctly.
It is right most of the times however there are occasions when the calling process cannot be trusted (ex. setuid executable).
On Windows: use
GetModuleFileName(NULL, buf, bufsize)
相关文章推荐
- Linux下获取当前进程的执行文件的绝对路径和所在目录(通过/proc/self/exe链接)
- 获取EXE及Dll文件路径信息
- 获取工程路径(兼容windows和linux)
- java web项目获取window/linux真实路径
- C++编程实现从注册表中获取程序安装路径并调用exe文件
- c++_获取当前程序(EXE)所在的路径
- c/c++ 获取当前程序(EXE)所在的路径
- 获取exe程序路径
- 获取EXE文件安装后的路径
- linux 下获取当前工作路径的方法
- 简单介绍Linux进程文件路径的获取方法
- MFC中获取exe所在路径(绝对路径)[转]
- 系统服务中获取本exe文件当前路径实例
- linux获取当前绝对路径[转自:http://www.linuxdiyf.com/viewarticle.php?id=84177]
- c#获取可运行程序(exe)路径问题
- linux 获取文件路径中的目录路径和文件名
- VC新建目录CreateDirectory、得到exe存放路径GetModuleFileName、获取当前目录GetCurrentDirectory、CFileDialog设置打开默认路径
- linux下获取程序所在目录绝对路径
- c/c++ 获取当前程序(EXE)所在的路径
- [Winform]通过lnk快捷方式获取exe所在的路径