Question
Write a 'Collatz' program to output the Collatz-Conjecture sequence (Refer to: https://en.wikipedia.org/wiki/Collatz_conjecture) Problem Statement: Implement the program by POSIX shared memory and structure your program
Write a 'Collatz' program to output the Collatz-Conjecture sequence (Refer to: https://en.wikipedia.org/wiki/Collatz_conjecture)
Problem Statement: Implement the program by POSIX shared memory and structure your program by the producer-consumer mode. The program should be written in two separate files 'Collatz-Producer.c' and 'Collatz-Consumer.c'.
(1) This program should work as follows:
(a) The producer process writes the contents of the sequence to the shared-memory object. Its main steps are listed as follows:
- Perform error checking to ensure that the input is valid.
- Establish the shared-memory object.
- Writes the contents of the shared memory.
(b) The consumer process outputs the sequence when the producer completes. Its main steps are listed as follows:
-
Open the shared-memory object.
-
Output the contents of the shared memory.
-
Remove the shared-memory object.
(2) Here is a sample run to help you with debugging:
./Collatz-Producer 35
Producer: Writing the sequence to the shared-memory object is done!
./Collatz-Consumer
Consumer: The output sequence is: 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1
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