Нужно написать код на языке Си
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
Что я уже пробовал:
У меня возникли проблемы с написанием этого кода. Мне нужна подсказка
Richard MacCutchan
Все подсказки находятся в вопросе, попробуйте прочитать его еще раз.