#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <linux/limits.h>
#include <libgen.h>
int main()
{
char exe[PATH_MAX], real_exe[PATH_MAX];
ssize_t r;
char *dir;
if ((r = readlink("/proc/self/exe", exe, PATH_MAX)) < 0)
exit(1);
if (r == PATH_MAX)
r -= 1;
exe[r] = 0;
if (realpath(exe, real_exe) == NULL)
exit(1);
dir = dirname(real_exe);
puts(dir);
}