Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
Task 3: Send a series of messages between producer and consumer (30 marks) Copy your code from Task 2 into a new directory named task3. Stage 1 Modify your producer so it can handle a series of messages. 1. Read a 20 character message from stdin and write it to the shared memory segment as per Task 2. 2. Print the message to stdout. 3. Sleep for 10 seconds. 4. Repeat steps 1–3 until EOF (end of file). 5. Detach and destroy the segment. Stage 2 Modify your consumer so it can read each message written by the producer. 1. Implement busy waiting to test for an available message. 2. Read the message from the shared memory segment and print it to stdout. 3. Clear the contents of the segment by writing a NULL termination character to every location. 4. Repeat steps 1–3 until there are no more messages. 5. Detach the segment and exit. You will need to determine how the consumer can detect when a new message is available. If it reads the message too early, it may only get part of it; if it reads it too late, the producer may have started writing the following message. Furthermore, you also need to determine how the consumer will know when there are no more messages. As the shared memory segment size is 32 bytes and you are only required to read messages up to 20 characters (bytes) in length, you have 12 bytes available to use for other information. Describe your strategy in your report. As with Task 2, test your solution using two terminal sessions. Stage 3 Once your producer and consumer are passing messages between one another, use the top command to monitor the CPU usage of both processes. On the VirtualBox Ubuntu VM, you can execute the following command to sort the list of processes by CPU utilisation and filter to those running as the current user. This should make it easier to monitor the producer/consumer. Discuss your observations in your report, noting the differences between the producer and consumer. $ top -u cnos -o %CPU

What I have tried:

I am having problem on writing this code. I need some hint
Posted
Updated 1-Nov-18 1:15am
Comments
Richard MacCutchan 1-Nov-18 5:30am    
The hints are all in the question, try reading it again.

This is not meant to be a mean spirited response to your question. It will, however seem harsh.

Find a another field of study. If you had any chance of being any good at all in writing computer programs you'd have a solution - even if it had bugs - to show us your work. More importantly:   to show you your work!

Find something you're good at and that you enjoy - or at least one of these two.
Do yourself a favor, now - life is too short to waste.

 
Share this answer
 
Comments
Leo Chapiro 1-Nov-18 9:22am    
Words of wisdom!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think! Start by reading the question carefully and put in the context of the rest of your course. Since this would appear to be an exam question, if you can't work out what to do by now, then either you weren't paying any attention during the actual course, or you are looking too far ahead and need to scale back you expectations until your skill level catches up!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 
Quote:
I am having problem on writing this code. I need some hint

You show no attempt to solve the problem yourself, you have no question, your main effort is pasting the requirement, you just want us to do your HomeWork.
HomeWork problems are simplified versions of the kind of problems you will have to solve in real life, their purpose is learning and practicing.
We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
 
Share this answer
 
For your homeworks you need to learn and develop some skill. Please read my article How to start the homeworks which describes a lot of your tasks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900