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

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!