Skip to content

Instantly share code, notes, and snippets.

@hewigovens
Last active May 15, 2020 02:33
Show Gist options
  • Save hewigovens/fed6b6ead5152da9af55 to your computer and use it in GitHub Desktop.
Save hewigovens/fed6b6ead5152da9af55 to your computer and use it in GitHub Desktop.
get executable path from libproc
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <libproc.h>
int main (int argc, char* argv[])
{
int ret;
pid_t pid;
char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
pid = getpid();
ret = proc_pidpath (pid, pathbuf, sizeof(pathbuf));
if ( ret <= 0 ) {
fprintf(stderr, "PID %d: proc_pidpath ();\n", pid);
fprintf(stderr, " %s\n", strerror(errno));
} else {
printf("proc %d: %s\n", pid, pathbuf);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment