Guest User

Untitled

a guest
Jan 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment