【发布时间】:2021-12-07 09:13:48
【问题描述】:
我在 process_B 的主线程的清理中有这个调用,它接收 IPC 消息队列上的消息:
if (msgctl(qId, IPC_RMID, NULL) < 0) {
perror("msgctl");
}
到达时,报告以下内容:
msgctl : Invalid argument
Error: failed to remove message queue.
我有另一个进程_A,它向进程_B 发送消息并且没有被关闭。
那么man msgctl里面就有这个说法……
IPC_RMID
Immediately remove the message queue, awakening all waiting
reader and writer processes (with an error return and errno set
to EIDRM). The calling process must have appropriate privileges
or its effective user ID must be either that of the creator or
owner of the message queue. The third argument to msgctl() is
ignored in this case.
我不清楚删除消息队列如何唤醒所有读者和作者。 process_A 是否也必须以某种方式关闭,然后 process_B 才能删除消息队列?
如果 process_B 关闭,我正在尝试清理资源以包含此消息队列。如果它重新启动,我希望 process_B 在清除队列后“重新连接”到消息队列,以防 process_A 从未关闭。可以清除队列吗?然后我当然会为 process_A 做同样的事情。
更新:(增加消息队列的开启):
key_t key = ftok(".", 'm');
int qid = msgget(key, IPC_CREAT | 0644);
if (qid == -1) {
perror("msgget");
return -1;
}
【问题讨论】:
-
你能说明你是如何打开你的消息队列的吗?
-
添加了开头。两个进程之间消息发送成功。
-
qid是否在您调用(msgctl(qId, IPC_RMID, NULL)的范围内?
标签: c ipc message-queue