Single sender and multiple receiver processes using posix message queue in linux
Asked Answered
T

1

11

Is there any way such that a writer process after sending a mesage to message queue using mq_send(), multiple reader processes can read the message using mq_receive(). I expect 1 write to mq and 1 read from mq, the message is lost.

So I just want to know if my understanding is wrong. Is there any way so that a single writer and multiple reader processes can communicate using posix message queues.

Trass answered 29/3, 2012 at 17:45 Comment(0)
T
12

Yes your understanding is correct. You can't do this reliably with POSIX message queues. If you want to communicate the same message to different threads/processes reliably you should use a different queue for each reader.

You can do this if you switch to SYSV message queues. Msgsnd() and msgrcv() can manipulate the message type field of a message in some agreed upon protocol. For instance the writer process will make the message type of the message the PID of the reader process; and the reader process will request to read only messages of that message type. Note that this still requires the writer to write a message for each reader process.

Tuberculosis answered 29/3, 2012 at 19:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.