代码


#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(++)获取可执行程序完整路径的更多相关文章

  1. Windows获取进程完整路径

    #include <stdio.h> #include <locale.h> #include <windows.h> #include <tlhelp32. ...

  2. linux C++ 获取文件绝对路径

    提供ftp服务时需要获取文件绝对路径,这里记录一下. #include <stdlib.h> #include <stdio.h> #include <limits.h& ...

  3. windows和linux下获取当前程序路径以及cpu数

    #ifdef WIN32 #include <Windows.h> #else #include <stdio.h> #include <unistd.h> #en ...

  4. QT 获取可执行程序的路径

    获取到生成.exe目录 QCoreApplication::applicationDirPath(); 获取当前工程目录 QDir::currentPath()

  5. Windows库函数获取 可执行程序所在路径

    头文件 #include <Windows.h> 函数 函数已经写好了 std::string get_executable_dir_() { char path[255] = { 0 } ...

  6. 四种方法获取可执行程序的文件路径(.NET Core / .NET Framework)

    原文:四种方法获取可执行程序的文件路径(.NET Core / .NET Framework) 本文介绍四种不同的获取可执行程序文件路径的方法.适用于 .NET Core 以及 .NET Framew ...

  7. Jquery EasyUI Combotree和 EasyUI tree展开所有父节点和获取完整路径

    Jquery EasyUI Combotree展开所有父节点 Jquery EasyUI Combotree获取树完整路径 Jquery EasyUI tree展开所有父节点 Jquery EasyU ...

  8. C++获取当前所有进程的完整路径

    实现代码 #include <stdio.h> #include <windows.h> #include <tlhelp32.h> #include <st ...

  9. Linux显示一个二进制文件或可执行文件的完整路径

    Linux显示一个二进制文件或可执行文件的完整路径 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ which halt /sbin/halt

随机推荐

  1. LVS-三种模式的配置详情

    NAT模式 实验环境 LVS1 VIP 192.168.31.66 DIP 192.168.121.128 WEB1 192.168.121.129 WEB2 192.168.121.130 安装与配 ...

  2. Linux文件系统属性和权限概念详解(包含inode、block、文件权限、文件软硬链接等)

    Linux中的文件属性 ls -lih 包括:索引节点(inode),文件类型,权限属性,硬链接数,所归属的用户和用户组,文件大小,最近修改时间,文件名等等 索引节点:相当于身份证号,系统唯一,系统读 ...

  3. Java日期时间操作基础——包含JDK1.8时间操作新特性

    JDK1.7日期时间操作 示例小结 public class DateTest { public static final String FORMAT_DATE = "yyyy-MM-dd& ...

  4. MapReduce04 框架原理Shuffle

    目录 2 MapReduce工作流程 3 Shuffle机制(重点) 3.1 Shuffle机制 3.2 Partition分区 默认Partitioner分区 自定义Partitioner分区 自定 ...

  5. 入坑不亏!我们最终决定将 70w+ 核心代码全部开源

    作者 | 一啸 来源 | 尔达 Erda 公众号 背景故事 2017 年初,我们基于 DC/OS (mesos + marathon) 开始构建端点自己的 PaaS 平台,核心任务就是解决公司的软件开 ...

  6. A Child's History of England.45

    To forgive these unworthy princes was only to afford them breathing-time for new faithlessness. They ...

  7. C++ 写出这个数

    题目如下: 读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式: 每个测试输入包含 1 个测试用例,即给出自然数 n 的值.这里保证 n 小于 1. 输出格式: 在一行内 ...

  8. 如何从 100 亿 URL 中找出相同的 URL?

    题目描述 给定 a.b 两个文件,各存放 50 亿个 URL,每个 URL 各占 64B,内存限制是 4G.请找出 a.b 两个文件共同的 URL. 解答思路 每个 URL 占 64B,那么 50 亿 ...

  9. jenkins的sonarqube之代码检测的两种方法

    #:sonarqube下载地址,我们安装6.7  高版本已经不支持MySQL和Mariadb(最小3G内存) https://www.sonarqube.org/downloads/ #:安装文档 h ...

  10. shell awk命令字符串拼接

    本节内容:awk命令实现字符串的拼接 输入文件的内容: TMALL_INVENTORY_30_GROUP my163149.cm6 3506 5683506 mysql-bin.000013 3273 ...