10 #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
21 if(asprintf(&path
, "/proc/%d/status", getppid()) == -1) return(EXIT_FAILURE
);
22 fh
= fopen(path
, "r");
23 if(!fh
) { perror("fopen"); return(EXIT_FAILURE
); }
24 while(fgets(lbuf
, ARRAYSIZE(lbuf
), fh
) != NULL
)
26 if(sscanf(lbuf
, "PPid: %d", &gppid
) == 1)
33 if(gppid
== 0) { errx(EXIT_FAILURE
, "Grandparent Pid not found"); }
35 if(asprintf(&path
, "/proc/%d/exe", gppid
) == -1) return(EXIT_FAILURE
);
36 len
= readlink(path
, linktarget
, ARRAYSIZE(linktarget
));
37 if(len
== -1) { perror("readlink"); return(EXIT_FAILURE
); }
38 printf("%.*s\n", len
, linktarget
);