#include #include #include #include #include #include #include main(int argc, char *argv[]) { int pid = 0; int fd[2], ct, newfd; char buf[200]; FILE *Parent_FP, *Child_FP, *Out_File; if (mkfifo("/tmp/New_FiFo", 777) < 0) { fprintf(stderr,"Mkfifo Failed. Bailing Out.\n"); exit(-299); } pid = fork(); switch (pid) { case -1: printf("Failed fork\n"); break; case 0: /* Child code */ fprintf(stdout," I am child. \n"); Out_File = fopen("ChildData","w"); Child_FP = fopen("/tmp/New_Fifo", "r"); // sleep(10); fscanf(Child_FP, "%s", buf); fprintf(stdout,"Child sez: %s", buf); fprintf(stdout,"\nChild sez: I am Done. \n"); fclose(Child_FP); exit(0); default: /* Parent code */ fprintf(stdout," I am parent. \n"); Parent_FP = fopen("/tmp/New_Fifo", "w"); // do // { fprintf(stdout," Parent Sez - Enter a string: "); fscanf(stdin, "%s", buf); fprintf(Parent_FP,"%s", buf); // } while (strcmp(buf,"DONE") == 0); fclose(Parent_FP); waitpid(pid, NULL, 0); unlink("/tmp/New_Fifo"); fprintf(stdout,"\nParent sez: Child exited - I am Done. \n"); exit(0); break; } }