Advertisement
Guest User

Untitled

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