// C program to implement one side of FIFO // This side writes first, then reads #include #include #include #include #include #include int main() { int fd; // FIFO file path char * myfifo = "/export/home/public/spiegel/cis552/demo/FIFO/myfifo"; printf("Start rw to get the prompt\n"); // Creating the named file(FIFO) // mkfifo(, ) mkfifo(myfifo, 0666); char arr1[80], arr2[80]; while (1) { // Open FIFO for write only fd = open(myfifo, O_WRONLY); // Take an input arr2ing from user. printf("Enter a string of up to 80 characters\n"); // 80 is maximum length fgets(arr2, 80, stdin); // Write the input arr2ing on FIFO // and close it // printf("About to write %s to pipe with descriptor %d\n",arr2,fd); write(fd, arr2, strlen(arr2)+1); // printf("Wrote %s to pipe with descriptor %d\n",arr2,fd); close(fd); // Open FIFO for Read only fd = open(myfifo, O_RDONLY); // printf("About to read from pipe with descriptor %d\n",fd); // Read from FIFO read(fd, arr1, sizeof(arr1)); // printf("Read %s from pipe with descriptor %d\n",arr1,fd); // Print the read message printf("User2: %s\n", arr1); close(fd); } return 0; }