Skip to content

Instantly share code, notes, and snippets.

@jintao-zero
Created September 27, 2017 08:11
Show Gist options
  • Save jintao-zero/88f0ce2083c681c418ff9bb49ca3491c to your computer and use it in GitHub Desktop.
Save jintao-zero/88f0ce2083c681c418ff9bb49ca3491c to your computer and use it in GitHub Desktop.
linux c/c++ get exe path
#include <string>
#include <iostream>
#include <limits.h>
#include <unistd.h>
std::string getexepath()
{
char result[ PATH_MAX ];
ssize_t count = readlink( "/proc/self/exe", result, PATH_MAX );
return std::string( result, (count > 0) ? count : 0 );
}
int main(int argc, char *argv[])
{
std::cout << getexepath() << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment