Pipe vs msg queue

前端 未结 2 1464
野趣味
野趣味 2021-02-12 14:25

What is the difference between message queues and a pipe in Linux?

2条回答
  •  悲&欢浪女
    2021-02-12 14:34

    They are very different things, really.

    The biggest practical difference is that a pipe doesn't have the notion of "messages", it's just a pipe to write() bytes to and read() bytes from. The receiving end must have a way to know what piece of data constitute a "message" in your program, and you must implement that yourself. Furthermore the order of bytes is defined: bytes will come out in the order you put them in. And, generally speaking, it has one input and one output.

    A message queue is used to transfer "messages", which have a type and size. So the receiving end can just wait for one "message" with a certain type, and you don't have to worry if this is complete or not. Several processes may send to and receive from the same queue.

    see man mq_overview and/or man svipc for more information.

提交回复
热议问题