How to get a unique POSIX message queue?

I am working on a simple parallel application in which I want to use a single process to store information about the status of a workflow family. It seems relatively easy to set up a POSIX message queue in which all worker bees can send periodic updates to the state support service. My problem? The POSIX message queue must have a name. I do not want to choose a name; all I care about is getting a unique message queue, just as I would use SYSV's message queues with IPC_PRIVATE. For a unique file name I could use mkstemp(3)or for a unique open file descriptor that I could use tmpfile(3). How do I get a unique POSIX message queue?

+5
source share
1 answer

I do not want to choose a name; all I care about is getting a unique message queue, just as I would use SYSV message queues with IPC_PRIVATE

Well, with POSIX message queues, you need to specify a name, but you do not need to save it and do not allow other users to use the same queue under this name.

IPC_PRIVATE facial expressions

Take that mkstempand tmpfiledo under the hood. Borrow any of the tmp / temp naming algorithms to create something / reasonably_unique, mq_openit is O_CREAT | O_EXCL and then mq_unlinkit. Then, the child worker processes can inherit the message queue descriptor.

. root EUID , , mq_open mq_unlink? .

SOCK_DGRAM socketpair pipe. POSIX — attr.mq_msgsize SO_SNDBUF/SO_RCVBUF PIPE_BUF, mq_notify / (, ) — .

+3

All Articles