SHARE
TWEET

Untitled

a guest Nov 12th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top