Last active
May 15, 2020 02:33
-
-
Save hewigovens/fed6b6ead5152da9af55 to your computer and use it in GitHub Desktop.
get executable path from libproc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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