daily pastebin goal
59%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/types.h>
  4. #include <stdlib.h>
  5. #include <sys/wait.h>
  6.  
  7. int a[4]={1,2,3,4};
  8. int main(){
  9.     int p[2];
  10.     pipe(p);
  11.     if (fork()==0){
  12.         a[2]+=a[3];
  13.         write(p[1], &a[2], sizeof(int));
  14.         exit(0);
  15.     }
  16.     a[0]+=a[1];
  17.     read(p[0], &a[2], sizeof(int));
  18.     a[0]+=a[2];
  19.     wait(0);
  20.     printf ("The answer is %d, and it should be 10.\n", a[0]);
  21.     close (p[1]);
  22.     close (p[0]);
  23.     return (0);
  24. }
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