// C program to implement one side of FIFO // This side reads first, then reads #include #include #include #include #include #include int main() { int fd1; // FIFO file path char * myfifo = "/export/home/public/spiegel/cis552/demo/FIFO/myfifo"; printf("Start wr to get the prompt\n"); // Creating the named file(FIFO) // mkfifo(,) mkfifo(myfifo, 0666); char str1[80], str2[80]; while (1) { // First open in read only and read fd1 = open(myfifo,O_RDONLY); // printf("About to read from pipe with descriptor %d\n",fd1); read(fd1, str1, 80); // printf("Read %s from pipe with descriptor %d\n",str1,fd1); // Print the read string and close printf("User1: %s\n", str1); close(fd1); // Now open in write mode and write // string taken from user. fd1 = open(myfifo,O_WRONLY); printf("Enter a string of up to 80 characters\n"); fgets(str2, 80, stdin); // printf("About to write %s to pipe with descriptor %d\n",str2,fd1); write(fd1, str2, strlen(str2)+1); // printf("Wrote %s to pipe with descriptor %d\n",str2,fd1); close(fd1); } return 0; }