Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include <sys/wait.h>
  4. #include <stdint.h>
  5. #include <stdlib.h>
  6.  
  7. int main() {
  8.     char tmp[4096];
  9.     uint32_t counter = 0;
  10.     while(1) {
  11.         pid_t p = fork();
  12.         if (p == 0) exit((scanf("%s", tmp) != EOF));
  13.         else {
  14.             int status;
  15.                         waitpid(p, &status, 0);
  16.             if (status == 0) break;
  17.             counter += WEXITSTATUS(status);
  18.         }
  19.     }
  20.     printf("%d", counter);
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement