Write a single C that uses fork and pipe. The program should first calculate the prime numbers between 2 and 1,000 inclusive.
Write a single C that uses fork and pipe. The program should first calculate the prime numbers between 2 and 1,000 inclusive. The program should then use fork to spawn 10 processes that will determine the remaining prime numbers from 1,001 to 1,000,000 inclusive. One child process should calculate the prime numbers from 1,001 to 100,000 inclusive. Another child process should calculate the prime numbers from 100,001 to 200,000 inclusive. Another child process should calculate the prime numbers from 200,001 to 300,000 inclusive. Another child process should calculate the prime numbers from 300,001 to 400,000 inclusive. Another child process should calculate the prime numbers from 400,001 to 500,000 inclusive. Another child process should calculate the prime numbers from 500,001 to 600,000 inclusive. Another child process should calculate the prime numbers from 600,001 to 700,000 inclusive. Another child process should calculate the prime numbers from 700,001 to 800,000 inclusive. Another child process should calculate the prime numbers from 800,001 to 900,000 inclusive. Another child process should calculate the prime numbers from 900,001 to 1,000,000 inclusive. Each child process should write its primes into a pipe that will be read by the parent process. Thus the parent process collects all the primes identified by the child processes. The program must be written in a way that all 10 child processes are executing concurrently. Thus, it is NOT acceptable for the parent process to spawn a child, read its primes, and then spawn another child process. Instead, the parent process must spawn all 10 child processes before reading the values written to the pipe by any of the child processes. After reading all the primes from all the child processes, the parent process writes them out to standard output, in ascending order, with one prime per line. Along with this assignment, you will find a "sample.out" file that contains the expected output from the program.

Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images









