我的程序使用系统消息队列进行 ipc .my 代码:
key = 0x0000ed79;
if( ( id=msgget(key,0666|IPC_CREAT)) <= 0 )
return false ;
else return true
问题是:
- 每次机器重启时,都会自动建立一个msgqueue,使用相同的key,但id为0,所以我必须ipcrm它;
为什么我不能使用 id 为 0 的 msgqueue?这是手册页中 msgget api 返回值的描述,看来 id 0 不是错误的:
If successful, the return value will be the message queue identifier(a nonnegative integer), otherwise -1 with errno indicating the error
最佳答案
how to find which process create the queue with the same key?
没有简单的方法可以找到哪个进程创建了队列,但是我们可以检查最后发送到队列或从队列接收的进程,也许创建进程就是其中之一(即使不是,也可以识别该进程使用队列可能会有所帮助),e。 G。对于 msqid 0
ipcs -qi0
显示lspid=… lrpid=…
- 最后发送/接收消息的进程的进程ID
来自关联的消息队列。
关于c - 为什么每次操作系统重启时都会自动构建msgqueue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20583895/