Message queues – creating the sender
Another popular IPC technique is message queues. It's pretty much what the name suggests. A process leaves messages in a queue, and another process reads them.
There are two types of message queues available on Linux: System V and POSIX. In this recipe, we'll cover POSIX message queues since these are a bit more modern and simpler to handle. POSIX message queues are all about using the mq_
functions, such as mq_open()
, mq_send()
, and so on.
Knowing how to use message queues enables you to choose from among a variety of IPC techniques.
Getting ready
For this recipe, we'll only need the GCC compiler and the Make tool.
How to do it…
In this recipe, we'll create the sender program. It's this program that will create a new message queue and some messages to it. In the next recipe, we'll receive those messages:
- Write the following code in a file and save it as
msg-sender.c
. Since there...