Question: Prime Number Generation You are asked to write a C code to generate prime numbers in a distributed manner by using signal and pipes hile


Prime Number Generation You are asked to write a C code to generate prime numbers in a distributed manner by using signal and pipes hile Input would bek the number of child prooesses, the output is the list of prime numbers. The parent process forks k child (identical) processes along with 2*k pipes-two for each parent-child pair one sends messages from parent to child, the other one from child to parent). Signals are AVAILABLE and BUSY modeled by integers. 1. Parent spawns k child processes 2 All k child processes will send AVAILABLE to the parent. 3. Parent will provide k random numbers to the child who is AVAILABLE. 4. After getting the numbers child will send a BUSY signal to parent. 5. Each child will check whether there is a prime number in this k random numbers. 1. IfYES it will send the numbers to parent. Parent will check whether it has got this prime already from any of the child processes. 1. IfYES then it will simply discard the number 2. Else it will insert it into array primearrl and increase the count numprime+t. primes and return. no available child process, it will wait for some child to become available. 1. If numprime 2*k then parent will kill all the child process and will report the 2. Else Parent will send next k random numbers to the child who is AVAILABLE. If 2. If NO prime found in the provided k numbers child will send AVAILABLE to the parent. 6. Again go to step 3 to 5. Prime Number Generation You are asked to write a C code to generate prime numbers in a distributed manner by using signal and pipes hile Input would bek the number of child prooesses, the output is the list of prime numbers. The parent process forks k child (identical) processes along with 2*k pipes-two for each parent-child pair one sends messages from parent to child, the other one from child to parent). Signals are AVAILABLE and BUSY modeled by integers. 1. Parent spawns k child processes 2 All k child processes will send AVAILABLE to the parent. 3. Parent will provide k random numbers to the child who is AVAILABLE. 4. After getting the numbers child will send a BUSY signal to parent. 5. Each child will check whether there is a prime number in this k random numbers. 1. IfYES it will send the numbers to parent. Parent will check whether it has got this prime already from any of the child processes. 1. IfYES then it will simply discard the number 2. Else it will insert it into array primearrl and increase the count numprime+t. primes and return. no available child process, it will wait for some child to become available. 1. If numprime 2*k then parent will kill all the child process and will report the 2. Else Parent will send next k random numbers to the child who is AVAILABLE. If 2. If NO prime found in the provided k numbers child will send AVAILABLE to the parent. 6. Again go to step 3 to 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
