linux 获取exe的路径
来源:互联网 发布:nba2k14优化伴侣 编辑:程序博客网 时间:2024/05/16 07:24
使用示例:
int bufsize = 1024;char buffer[bufsize];readlink("/proc/self/exe", buf, bufsize);
To summarize:
On Unixes with
/proc
really 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
$PATH
for executableargv[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 获取exe的路径
- exe获取自己的路径
- C#获取exe的路径
- 获取EXE文件安装后的路径
- 获取进程所在的exe路径
- 获取.EXE可执行文件所在的目录路径
- MFC获取exe文件所在的路径
- BCB如何获取.exe所在的路径?
- python获取自己的exe路径
- mfc 获取当前exe的路径
- 获取exe所在文件的路径
- java 获取打包成exe后的exe程序路径
- 获取exe程序路径
- C++ 获取exe路径
- C++ 获取exe路径
- 获取当前工程的.exe文件的路径和目录
- c# 关于获取exe路径
- 获取exe和dll路径
- compass指南针搜索框架学习(二)
- 使用iOS手势UIGestureRecognizer
- 用QextSerialPort库,获取系统当前可用串口信息的方法
- android App 缓存管理
- compass 简单教程
- linux 获取exe的路径
- 统计学习-1
- UniDAC使用日记
- 【孩子分糖 Candy problems】可行解3-leecode-OJ
- Android数据库(SQLiteDatabase)使用小结 .
- 初探js特效魅力之定时器的使用one
- const的作用
- ALAsset和ALAssetRepresentation详解
- 简单TCP 循环服务器