Question
Overview: Write a C++ wrapper [embeds with C] program called pipeLab.cpp that creates a pipe channel and then a child process to communicate via the
Overview:
Write a C++ wrapper [embeds with C] program called pipeLab.cpp that creates a pipe channel and then a child process to communicate via the pipe with the parent. The parent writes to a pipe with multiple random numbers while the child reads numbers from the pipe and do some statistical calculations. When done, both processes print their messages and exit the program.
Details: The parent calls first the pipe system-call and creates the pipe, then calls the fork to create the child. After that, both parent and child prepare a one-way pipe channel, where the parent fills the pipe one-at-a- time with random numbers [i.e. items] until certain limit [num Items] is reached. The child reads these numbers one-at-a- time, update the received data, and at the end finds the min, max and avg (average) of all number received, and prints the results on the screen with its own real ID [i.e. using getpic() system call]:
Child ID: number items received: n, min: xx, max: yy, avg: zz.z
When parent is done, it waits first the child to be terminated by using wait() system call. Then the parent prints:
Parent ID: number items written into the pipes are: nn
The program uses argc & argv to pass three (3) parameters to the program:
1. The 1st item is numItems [e.g. 200], to generate
2. The 2nd item refers to range of the numbers [e.g. 1000]
3.The 3rd item refers to seed of the random number generator [e.g. 3127] where the argv[0] has the name of the executable program [i.e. pipeEx].
The parent generates random numbers in the range 0 to 999 ( modulo division by 1000).
In this program, t here is only one pipe, to pass the random numbers from parent process to child. Parent & child use getpid(void) system call to get and print their real IDs.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started