6

Among the following list of IPC options, which could perform multicast (i.e. 1 sender and multiple receivers):

  • signals
  • half duplex pipe
  • named pipe
  • system V message queue
  • unix domain socket

Edit

  • memory mapped files

From my understanding, it might be possible with named pipe (not sure).

Jake
  • 16,329
  • 50
  • 126
  • 202
  • This sounds like a question from your homework, not a practical programming question. – Barmar Feb 28 '15 at 00:54
  • You can have multiple readers of a message queue or pipe, but only one of them will be able to read any particular message. – Barmar Feb 28 '15 at 00:56
  • 3
    Its not homework for sure. I'm just trying to do a comparison. – Jake Feb 28 '15 at 00:56
  • Unix domain sockets don't support multicast in POSIX, but Linux adds this as an extension. https://lkml.org/lkml/2012/2/20/208 – Barmar Feb 28 '15 at 00:58
  • So I think the general answer is that none of them do. – Barmar Feb 28 '15 at 01:00
  • Forgot to add .. what about memory mapped files ? – Jake Feb 28 '15 at 02:46
  • You can send the data to multiple receivers that way, but you need a way to notify all of them that there's new data to read. I guess they could poll, though. But in that case, you could just use an ordinary file, you don't need memory mapping. – Barmar Feb 28 '15 at 22:00
  • This looks related: [Is there a way for multiple processes to share a listening socket?](https://stackoverflow.com/q/670891/608639) – jww Oct 08 '18 at 11:46
  • @Barmar it looks like this patch series was never merged into the upstream kernel. – maxschlepzig May 16 '21 at 18:59

1 Answers1

4

There's nothing as conceptually flexible as multicast, but with a few limitations some of the facilities might do what you want.

Signals may be delivered to a process group. The other IPC mechanisms you list have a sender/receiver model and are not suitable for multicast, barring local extensions like Linux's multicast AF_UNIX sockets as @Barmar points out in the comments.

If you only need to send a single "signal" to descendant processes, and only once, you may use an inherited fifo. All receivers inherit the read end of the fifo but not the write end. The process holding the write end closes it at some point, and all receivers will detect EOF on their read end copies.

pilcrow
  • 56,591
  • 13
  • 94
  • 135