Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

posix

sysv

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.

like image 923
jagadeesh Avatar asked Mar 29 '12 17:03

jagadeesh


1 Answers

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.

like image 163
Duck Avatar answered Sep 18 '22 11:09

Duck