Single sender and multiple receiver processes using posix message queue on Linux

Is there a way for the write process after sending the message to the message queue using mq_send() , several reading processes can read the message using mq_receive() . I expect 1 to write to mq and 1 to read with mq , the message will be lost.

So I just want to know if I misunderstand. Is there a way in which a single writer and several reading processes can interact using posix message queues.

+6
source share
1 answer

Yes, your understanding is correct. You cannot do this reliably with POSIX message queues. If you want to reliably transmit the same message to different threads / processes, you must use a different queue for each reader.

This can be done if you switch to SYSV message queues. Msgsnd () and msgrcv () can handle the message type field of a message in some consistent protocol. For example, the writing process will make the message type of the PID message of the reading process; and the reading process will request to read only messages of this type of message. Note that this still requires the writer to write a message for each reading process.

+7
source

Source: https://habr.com/ru/post/911963/


All Articles