我正在使用msgget()syscall来获取新的消息队列。我在其中使用了IPC_CREAT和IPC_EXCL标志。喜欢message_queue = msgget(ftok("/tmp", 100), (0666 | IPC_CREAT | IPC_EXCL));
现在,当我的编程序意外存在时,消息队列仍然存在,并且我无法重新创建消息队列。因此,我的问题是“如何获取现有的消息队列的ID?”
顺便说一句,消息队列在哪里存储其ID?
最佳答案
Regd“如何获取现有的消息队列的ID?”
来自man msgget
If msgflg specifies both IPC_CREAT and IPC_EXCL and a message queue already exists for key, then msgget() fails with errno set to EEX-
IST. (This is analogous to the effect of the combination O_CREAT | O_EXCL for open(2).)
尝试不使用IPC_EXCL标志。
Regd。消息队列在哪里存储其ID
来自man proc
/proc/sysvipc
Subdirectory containing the pseudo-files msg, sem and shm. These files list the System V Interprocess Communication (IPC)
objects (respectively: message queues, semaphores, and shared memory) that currently exist on the system, providing similar
information to that available via ipcs(1). These files have headers and are formatted (one IPC object per line) for easy under-
standing. svipc(7) provides further background on the information shown by these files.
关于c - 如何获取现有的消息队列ID,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10024211/