Question: Write a program that uses two pipes to enable bidirectional communication between a parent process and a child process. Your program must perform the follow

 Write a program that uses two pipes to enable bidirectional communication

Write a program that uses two pipes to enable bidirectional communication between a parent process and a child process. Your program must perform the follow actions: 1. The parent process loops, reading one character (i.e. 1 byte) of text from standard input (stdin). The byte is then sent to the child process using one of the two pipes. 2. The child receives the character via the pipe, converts the character to uppercase, and then sends the capitalized character (i.e. 1 byte) back to the parent via the other pipe. 3. Within its loop, the parent reads the byte coming back from the child and echos it to standard output (as a character, i.e. printf("%c", data) before continuing its next loop iteration to read the next character from stdin. 4. The parent loops in this fashion (reading a byte from stdin, sending it to the child, wait for modified byte from child, read next byte from stdin, etc) until stdin encounters EOF. If the parent receives EOF from stdin, your program (which consists of two processes) must begin to terminate. This consists of the following: (a) The parent closes its ends of both pipes and begins gracefully terminating itself, including fulfilling any responsibilities it has to the child process, etc. (b) The child process recognizes the closure of the pipe it is reading from (remember, a read() from the pipe will at this point result in receiving an EOF since the write end is closed). As a result, the child terminates gracefully, first fulfilling any outstanding obligations with respect to pipes, etc. Hints: Use read (STDIN_FILENO, ...) to read from standard input one byte at a time. What does read() return? What does read() return when it encounters the end of a file (i.e. EOF)? Read the manual pages: man 2 pipe, man 3 pipe, man 2 read, man 2 close, and man 3 toupper You can test your program by piping a text file into your program using: cat text.txt |./pipes or, more eloquently: ./pipes

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!