proc.c 787 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /* a simple helloworld test */
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include <stdio.h>
  7. #include <dirent.h>
  8. #include <fcntl.h>
  9. #include <sys/wait.h>
  10. int main(int argc, char ** argv)
  11. {
  12. for (int i = 0 ; i < 3 ; i++) {
  13. pid_t pid = fork();
  14. if (pid < 0) {
  15. perror("fork");
  16. exit(1);
  17. }
  18. if (pid) {
  19. waitpid(pid, NULL, 0);
  20. exit(0);
  21. }
  22. }
  23. struct dirent * dirent;
  24. DIR * dir = opendir("/proc");
  25. while ((dirent = readdir(dir)))
  26. printf("found %s\n", dirent->d_name);
  27. closedir(dir);
  28. return 0;
  29. }