Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/wait.h>
  4.  
  5. int
  6. main(void)
  7. {
  8. setbuf(stdout, NULL);
  9. FILE *fp = fopen("eee", "r");
  10.  
  11. int num, i=0;
  12. pid_t pid;
  13. while(fscanf(fp, "%d", &num) != EOF) {
  14. i++;
  15. fflush(fp);
  16. pid = fork();
  17. if (pid < 0) {
  18. printf("%d\n", -1);
  19. fflush(stdout);
  20. _exit(0);
  21. } else if (pid > 0) {
  22. waitpid(pid, NULL, 0);
  23. printf("%d\n", num);
  24. fflush(stdout);
  25. _exit(0);
  26. }
  27. //printf("sss");
  28. }
  29. printf("%d\n", i);
  30. //printf("Hello, Dcoder!");
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement