Message queues – creating the receiver
In the previous recipe, we built a program that created a message queue named /my_queue
, and then sent three messages to it. In this recipe, we'll create a program that receives the messages from that queue.
Getting ready
Before you start this recipe, you need to have completed the previous recipe. Otherwise, there will be no messages for us to receive.
You'll also need the GCC compiler and the Make tool for this recipe.
How to do it…
In this recipe, we'll receive the messages we sent in the previous recipe:
- Write the following code in a file and save it as
msg-receiver.c
. This code is a bit longer than the code for the sending program, so it's been broken up into several steps, each one explaining a bit of the code. Remember, though, that all the code goes into the same file. We'll start with the header files, the variables, the struct, and a character pointer namedbuffer
. We&apos...