Question: Problem 3 In this program you will use shared memory objects as well as pipes for interprocess communication. Write a C program on Linux that
Problem 3 In this program you will use shared memory objects as well as pipes for interprocess communication.
Write a C program on Linux that reads input on standard input, writes the same input on standard output, and also writes the hexadecimal equivalent of the input on standard error.
The program should do this by creating two children, parent sending the input via a pipe to the children, and reading the result of the child from shared memory.
To be more specific, the parent creates two children, child A and child B. The parent sends an identical file to both children through pipe, both children create a separate shared memory object (shared with the parent). Child As shared memory object size is equal to the size of the input and Child Bs should be twice the size of input (for hexadecimal representation).
Child A is responsible for simply writing what it receives through pipe to its shared memory, and child B is responsible for converting anything it receives to hexadecimal format and then writing it to its shared memory.
Once they are done writing the result to the shared memory objects, they send a message 'done' to the parent. Once the parent receives 'done', it reads the content of the shared memory, and for child A outputs to standard output, and for child B, outputs to standard error.
Part I:
Test your program manually. Once you are confident the program works fine, test it using a small input file with the size less than 64KB.
Hint: the file size should be smaller than the pipe size.
Part II:
Repeat the part I but this time instead of using a small input file, test it using a large input file via the command below, which provides the Linux dictionary as the input to the program, and writes the outputs to two separate files, which you can then verify manually: $ ./myprogram output-normal.txt 2>output-hex.txt
Hint: You will have to read the pipes from parent to children multiple times.
You may need to use sleep(), kill() and fork() system calls. Please also include a snapshot of the execution in terminal for each part.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
