Question: Task 2: Send a single message from producer to consumer (20 marks) Copy your code from Task 1 into a new directory named task2. Stage

Task 2: Send a single message from producer to consumer (20 marks) Copy your code from Task 1 into a new directory named task2. Stage 1 Modify your producer so it: 1. Attaches the shared memory segment (maps it to the address space of the process). 2. Initialises the segments contents by writing a NULL termination character to every location. 3. Reads a message of up to 20 characters from stdin (standard input) and writes it to the segment. You can either type the message in manually or use input redirection (Lab 2) to read from a file. 4. Prints the message to stdout (standard out). 5. Sleeps for 10 seconds. 6. Detaches (unmaps) and destroys the shared memory segment. Stage 2 Create a second C program in a file named consumer.c that: 1. Attaches to the shared memory segment created by the producer. 2. Reads the message stored in the segment and prints it to stdout. 3. Detaches the shared memory segment. 4. Exits, returning an appropriate status code.

note: its is c programming so according to the requirement of the task need two seprate program one is producer and other consumer

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!