5

I Read about message queue operations such as msgget(), msgsnd() and msgrcv(). But when I was searching for message queue related questions on stack overflow, I came to know there is another set of message queue operations such as mq_open(), mq_send(), mq_receive(). Can any one please let me know what are the differences between these 2 types of message queues and which type of message queues are extensively being used?

kadina
  • 5,042
  • 4
  • 42
  • 83

2 Answers2

11

The msgXXX family is inherited from SysV. The mq_XXX family was created by POSIX. Both families are however part of POSIX.

The two families have somewhat different feature sets the most important being that the SysV variant allows for the specification of different message types. This provides for flexibility in the way messages are processed and in assigning priorities. The POSIX family in contrast always returns the oldest message with the highest priority.

As a rule the POSIX family is the better choice unless there is something about SysV that you really need to use. The POSIX interface is also less cumbersome. An added bonus (on Linux) is that the POSIX mqd_t type representing a queue identifier is actually a file descriptor. This allows for the extremely convenient use of POSIX queues with select, poll and similar facilities.

Duck
  • 26,924
  • 5
  • 64
  • 92
6

Basicly, msgget, msgsnd, msgrcv are System V IPC, while mq_open, mq_send, mq_receive are POSIX IPC.

A good explaination: System V IPC vs POSIX IPC

Oracle Document for System V IPC

Oracle Document for POSIX IPC

In summary, POSIX IPC is designed after System V IPC. So a lot of old systems support only System V IPC while new systems begin to support POSIX IPC as well. And, because POSIX IPC can learn the advantages and disadvantages from System V IPC, POSIX IPC may be designed and implemented better. A notable difference is that all the POSIX IPC interfaces are thread safe.

Community
  • 1
  • 1
nicky_zs
  • 3,633
  • 1
  • 18
  • 26
  • 1
    SysV interfaces are also thread safe. There would be no point to them otherwise. – Duck Jul 16 '14 at 19:05
  • Well, I didn't confirm it but just read it from docs.oracle.com/cd/E19455-01/806-4750/6jdqdfltf/index.html that SysV IPC may not thread safe: *Unlike the System V IPC interfaces, the POSIX IPC interfaces are all multithread safe.* @Duck – nicky_zs Jul 16 '14 at 23:37