Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

Name and define four standards of proof.

Answered: 1 week ago

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago