#include #include int main() { int pipes[2]; int messagelen = 22; char data[50]; int childPID; int value, value2; srand(time(0)); pipe(pipes); childPID = fork(); if(childPID != 0) { // remember - if fork returns a non-zero value, this is the parent value = 20; value2 = 100; strcpy(data, "Go clean your room! from Parent"); messagelen = strlen(data); write(pipes[1], &value, sizeof(int)); write(pipes[1], &value2, sizeof(int)); wait(-1); read(pipes[0], &value, sizeof(int)); printf("Parent received %d\n", value); } else { read(pipes[0], &value, sizeof(int)); read(pipes[0], &value2, sizeof(int)); printf("Child %d value1= %d, value2 = %d\n", getpid(), value, value2); value = rand()%100; printf("Child sending %d to parent\n", value); write(pipes[1], &value, sizeof(int)); } } /* gcc -o fork3 fork3.c ./fork3 Child 18988 value1= 20, value2 = 100 Child sending 54 to parent Parent received 54 */