fork download
  1.  
  2. #include <errno.h>
  3. #include <fcntl.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7.  
  8. int main(int argc, char **argv) {
  9. size_t i;
  10. int open_max;
  11.  
  12. open_max = sysconf(_SC_OPEN_MAX);
  13. if (open_max < 0)
  14. return EXIT_FAILURE;
  15. for (i = 0; i < open_max; i++) {
  16. int f;
  17. int closed;
  18. closed = fcntl(i, F_GETFD, &f) == -1 &&
  19. errno == EBADF;
  20. if (!closed)
  21. printf("FD:%zu\n", i);
  22. }
  23.  
  24. return EXIT_SUCCESS;
  25. }
  26.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
FD:0
FD:1
FD:2
FD:9