Take the 2-minute tour ×  Is there a way in C/C++ to find the
location (full path) of the current executed program?  (The
problem with argv[0] is that it does not give the full path.)
share|improve this question which operating system? –  anon Jun
1 '09 at 7:38 Good answer here also:
stackoverflow.com/questions/1023306/… –  ergosys Sep 10 '11 at
19:32 This question ("How can I find the location of my program
in SETTING X?") could really use a tag; it's hard to search for
using keywords! –  SamB Feb 12 '12 at 22:32 add comment  10
Answers  up vote 106 down vote accepted  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) appen