posix message queue question

Hello

It seems to work to have a proccess create a message queue with msgget, write the returned descriptor to a file and have a second proccess read that file and use the descriptor without any proccess-local initialization...

Are message queue identifiers just (statically mapped mq-id <-> mq-handle) integer numbers to the UNIX IPC interface (and can therefore safely be passed as such), or are they regular handles to the proccess/session structure content (like file descriptors or terminal handles)?


Thanks in advance,
Alonso
 
Regarding terminology, the API you are asking about is generally known as "System V message queues" or "XSI message queues". "POSIX message queues" use mq_open() and related functions. Another option is Unix domain sockets.

You are right that the "identifier" is a system-wide number persistent until the system is rebooted or the message queue is removed. You can view current message queues and their identifiers with ipcs() and remove stale ones manually with ipcrm().

The "key" was originally intended to name IPC objects directly or to find IPC objects via files using ftok() but that is prone to collisions even if there is no attacker trying to cause collisions to deny service.
 
Back
Top