#include #include #include #include int main() { struct timespec ts1, ts2; pid_t newpid; int fd1[2], fd2[2]; char m0[] = "\n about to fork ..\n"; char m1[] = "message from parent to child\n"; char m2[] = "message from child to parent\n"; char m3[] = "\n done ..\n"; char rbuf1[256]; char rbuf2[256]; int cn1, cn2; if ((pipe(fd1)== -1)) printf(" error \n"); if ((pipe(fd2)== -1)) printf(" error \n"); printf("fd1 %d %d fd2 %d %d \n", fd1[0], fd1[1], fd2[0], fd2[1]); if ((newpid = fork()) == -1) { printf("error \n"); return 0;} if (newpid > 0) { close(fd1[1]); close(fd2[0]); // dup(fd2[1]); //close(fd2[1]); write(6, m1, sizeof(m1)); usleep(10000); cn1 = read(3, rbuf1, 256); write(1, rbuf1, cn1); } else { close (fd1[0]); close (fd2[1]); //dup (fd2[0]); //close (fd2[0]); write(4, m2, sizeof(m2)); usleep(10000); cn2 = read(5, rbuf2, 256); write(1, rbuf2,cn2); } write(2,m3,sizeof(m3)); return 0; }