Linux C(++)获取可执行程序完整路径
代码
#include <sys/statfs.h>
#include <string>
#include <iostream>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
/// get executable path
std::string get_cur_executable_path_()
{
char *p = NULL;
const int len = 256;
/// to keep the absolute path of executable's path
char arr_tmp[len] = {0};
int n = readlink("/proc/self/exe", arr_tmp, len);
if (NULL != (p = strrchr(arr_tmp,'/')))
*p = '\0';
else
{
return std::string("");
}
return std::string(arr_tmp);
}
int main(int argc, char* argv[], char* env[])
{
std::string exec_str = get_cur_executable_path_();
std::cout << "str=" << exec_str << "\n\n";
return 0;
}
输出结果

Linux C(++)获取可执行程序完整路径的更多相关文章
- Windows获取进程完整路径
#include <stdio.h> #include <locale.h> #include <windows.h> #include <tlhelp32. ...
- linux C++ 获取文件绝对路径
提供ftp服务时需要获取文件绝对路径,这里记录一下. #include <stdlib.h> #include <stdio.h> #include <limits.h& ...
- windows和linux下获取当前程序路径以及cpu数
#ifdef WIN32 #include <Windows.h> #else #include <stdio.h> #include <unistd.h> #en ...
- QT 获取可执行程序的路径
获取到生成.exe目录 QCoreApplication::applicationDirPath(); 获取当前工程目录 QDir::currentPath()
- Windows库函数获取 可执行程序所在路径
头文件 #include <Windows.h> 函数 函数已经写好了 std::string get_executable_dir_() { char path[255] = { 0 } ...
- 四种方法获取可执行程序的文件路径(.NET Core / .NET Framework)
原文:四种方法获取可执行程序的文件路径(.NET Core / .NET Framework) 本文介绍四种不同的获取可执行程序文件路径的方法.适用于 .NET Core 以及 .NET Framew ...
- Jquery EasyUI Combotree和 EasyUI tree展开所有父节点和获取完整路径
Jquery EasyUI Combotree展开所有父节点 Jquery EasyUI Combotree获取树完整路径 Jquery EasyUI tree展开所有父节点 Jquery EasyU ...
- C++获取当前所有进程的完整路径
实现代码 #include <stdio.h> #include <windows.h> #include <tlhelp32.h> #include <st ...
- Linux显示一个二进制文件或可执行文件的完整路径
Linux显示一个二进制文件或可执行文件的完整路径 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ which halt /sbin/halt
随机推荐
- [R] 添加误差棒的分组折线图:geom_path: Each group consists of only one observation. Do you need to adjust the...
想做一个简单的分组折线图,并添加误差棒,类似下面这样的: 用ggplot似乎很简单就能实现:ggplot+geom_errorbar+geom_line+geom_point,重点在于计算误差棒. 还 ...
- Demo04分解质因数
package 习题集1;import java.util.Scanner;//将一个正整数分解质因数.例如输入90,打印出90=2*3*3*5public class Demo04 { public ...
- 我的分布式微服务框架:YC-Framework
YC-Framework官方文档:http://framework.youcongtech.com/ YC-Framework源代码:https://github.com/developers-you ...
- A Child's History of England.33
To strengthen his power, the King with great ceremony betrothed his eldest daughter Matilda, then a ...
- Gradle入门及SpringBoot项目构建
https://blog.csdn.net/qq_27520051/article/details/90384483 一.介绍 Gradle 是一种构建工具,它抛弃了基于XML的构建脚本,取而代之的是 ...
- Data Calendar
1.Date对象 Date类在java.util包中.使用Date类的无参数构造方法创建的对象可以获取本地当前时间. 用Date的构造方法Date(long time)创建的Date对象表 示相对19 ...
- Java设计模式—Proxy动态代理模式
代理:设计模式 代理是一种常用的设计模式,其目的就是为其他对象提供一个代理以控制对某个对象的访问.代理类负责为委托类预处理消息,过滤消息并转发消息,以及进行消息被委托类执行后的后续处理. 图 1. 代 ...
- 【Linux】【Problems】在fedora 9上解决依赖问题
summary: 在32bit的fedora9上安装EMC客户端遇到无法解决的依赖问题 detail: rpm 安装: [root@hcszmons02 tmp]# rpm -ivh lgtoclnt ...
- OceanBase 2.x体验:推荐用DBeaver工具连接数据库
Original MQ4096 [OceanBase技术闲谈](javascript:void(0) 2020-01-15 OceanBase 2.x体验:推荐用DBeaver工具连接数据库 Ocea ...
- C# 使用管理员权限运行程序
最近在开发OPCServer组件过程中,在注册opcServer是总是返回false,后来查找原因得知在本地主机注册opcServer时,需要使用管理员权限. OPCServer在一台机器上部署时只需 ...