/*This program has two pipes. The program itself splits into /*a parent and a child process. The first pipe, pfdP, allows the parent to /*send a message tro the child. The second pipe, pfdQ. allows the child to /*send a message to the parent.*/ #include #include #include #include #include int main(void) { static int pfdP[2], pfdQ[2]; int pid, i, n; char messageParent[28]; /*pipe error message*/ if (pipe(pfdP) < 0 || pipe(pfdQ) < 0){ printf("write error"); } /*Fork program into parent, child processes*/ /*w/ error message*/ if ((pid = fork()) < 0) { printf("fork error\n"); } /*The child process*/ if (pid == 0){ /*The child process recieving a message from the parent*/ close(pfdP[1]); n = read(pfdP[0], messageParent, 28); printf("%s\n", messageParent); /*The child writing into the pfdQ pipeline*/ close(pfdQ[0]); write(pfdQ[1], "Child talking through parent", 28); _exit(0); } /*The parent process*/ else if (pid > 0){ /*The parent writing into the pfP pipeline, to the child*/ close(pfdP[0]); write(pfdP[1], "Parent talking through child", 28); /*The parent process recieving a message from the pfdQ pipeline, from the child*/ close(pfdQ[1]); n = read(pfdQ[0], messageParent, 28); printf("%s\n", messageParent); exit(0); } return(0); }