Question: Write a C program, which demonstrates interprocess communicationIPC between three processes using pipes. Your program as the parent process should create two child processes and

Write a C program, which demonstrates interprocess communicationIPC between three processes using pipes. Your program as the parent process should create two child
processes and utilize four pipes, establishing a multi-directional communication as shown in the figure below:
Note that unnecessary pipe ends must be closed to prevent improper pipe usage. Each pipe needs one write
one read end to remain open for two way communication.
The parent process should read a filename as a command line argument (so that different files can be used on
each execution). Each file should have an unspecified number of random integers. The parent process P1
should read integers and send to BOTH child processes one by one.
P2 receives the integers one by one, categorizes each integer according to number of digits. For
readability, implement a function named int nrDigits(int) to do this. You may assume integer
numbers in the test files be between 0 and 99999. Count the number of integers received according
to the number of digits.
P3 receives the integers one by one, computes the number of prime integers received. Implement a
function named int isPrime(int) to do this.
When P2 and P3 have finished their jobs, they must submit back the results they have computed back
to the parent process and terminate.
Parent process P1, after receiving results from P2 and P3 should print a nicely formatted output as
given in the following example and should terminate
Sample Output for 3 input files
$ ./homework1 numbers.txt $ ./homework1 numbers2.txt $ ./homework1 numbers3.txt
Input file: numbers.txt Input file: numbers2.txt Input file: numbers3.txt
1 digits -01 digits -61 digits -0
2 digits -42 digits 622 digits -0
3 digits -213 digits 5293 digits -10
4 digits -2834 digits 48754 digits 58
5 digits -6925 digits -130265 digits -182
Primes -108 Primes -1986 Primes -34
Nonprimes -892 Nonprimes 16514 Nonprimes 216
 Write a C program, which demonstrates interprocess communicationIPC between three processes

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!