SHARE
TWEET

Untitled

a guest Nov 19th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
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