fork download
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include <stdint.h>
  6.  
  7. #define BSIZE 200
  8.  
  9. int main(void) {
  10. char buffer[BSIZE];
  11. int const pid = getpid();
  12. snprintf(buffer, BSIZE, "/proc/%d/maps", pid);
  13. FILE * const maps = fopen(buffer, "r");
  14. while (fgets(buffer, BSIZE, maps) != NULL) {
  15. unsigned long from, to;
  16. int const r = sscanf(buffer, "%lx-%lx", &from, &to);
  17. if (r != 2) {
  18. puts("!");
  19. continue;
  20. }
  21. if ((from <= (uintptr_t)&fopen) && ((uintptr_t)&fopen < to)) {
  22. char const * name = strchr(buffer, '/');
  23. if (name) {
  24. printf("%s", name);
  25. } else {
  26. puts("?");
  27. }
  28. }
  29. }
  30. fclose(maps);
  31. }
  32.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
/lib/x86_64-linux-gnu/libc-2.24.so