Post by adarais there any way to get the process full path in C (not using argv)
example will be great !!
Try using dladdr() on main, then realpath() on that. Example attached.
Jonathan Schilling
$ cat fullpath.c
#include <stdio.h>
#include <dlfcn.h>
#include <assert.h>
#include <stdlib.h>
#include <sys/param.h>
int main() {
Dl_info dli;
int ret = dladdr((void*)main, &dli);
assert(ret);
char buf[MAXPATHLEN];
void* p = realpath(dli.dli_fname, buf);
assert(p);
printf("main() is contained in file %s\n", buf);
}
$ cc -o fullpath fullpath.c
$ ./fullpath
main() is contained in file /lfs/home/jls/test/fullpath
$ cd /tmp
$ /home/jls/test/fullpath
main() is contained in file /lfs/home/jls/test/fullpath