Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <stdlib.h>
- #include <sys/wait.h>
- int a[4]={1,2,3,4};
- int main(){
- int p[2];
- pipe(p);
- if (fork()==0){
- a[2]+=a[3];
- write(p[1], &a[2], sizeof(int));
- exit(0);
- }
- a[0]+=a[1];
- read(p[0], &a[2], sizeof(int));
- a[0]+=a[2];
- wait(0);
- printf ("The answer is %d, and it should be 10.\n", a[0]);
- close (p[1]);
- close (p[0]);
- return (0);
- }
Add Comment
Please, Sign In to add comment