如何清理 IPC 消息队列?

发布于 2024-08-07 10:27:20 字数 65 浏览 5 评论 0原文

我在基于 IPC 的应用程序中使用 msgget() 函数。如何清理充满旧消息队列的队列?

I am using msgget() function in my IPC based application. How can I clean up the queue filled up with old message queues?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

枫林﹌晚霞¤ 2024-08-14 10:27:20

要删除队列,请使用以下命令:

msgctl(msgQID, IPC_RMID, NULL);

系统调用:msgctl()

To delete a queue, use the following command:

msgctl(msgQID, IPC_RMID, NULL);

SYSTEM CALL: msgctl()

梦言归人 2024-08-14 10:27:20

您可以使用mq_setattr更改O_NONBLOCK的消息队列属性。
然后通过读取所有消息来清空队列,直到返回值指示队列为空。
现在恢复旧属性。

此方法不是运行时优化的,但它避免了关闭和打开消息队列的需要。

You can change the message queue attribute for O_NONBLOCK by using mq_setattr.
Then empty the queue by reading all of the messages, until the returned value indicates the queue is empty.
Now set back the old attributes.

This method is not a run time optimized, but it avoids the need to close and open the message queue.

相权↑美人 2024-08-14 10:27:20

解决方法是增加 MSGMNI 系统范围内消息队列的最大数量:取决于策略(在 Linux 上,可以通过 /proc/sys/kernel/msgmni 读取和修改此限制>)。

A work around is to increase MSGMNI System wide maximum number of message queues: policy dependent (on Linux, this limit can be read and modified via /proc/sys/kernel/msgmni).

蘑菇王子 2024-08-14 10:27:20

这些持久的资源分配问题(共享内存也有类似的问题)是 System V API 通常被认为已弃用的原因。在这种情况下,您是否考虑过使用unix域套接字或FIFO来代替消息队列?它们出现在文件系统中,当不再使用 rm 等工具时可以“清理”。

These persistent resource allocation issues (there's a similar one with shared memory) are why the System V APIs are generally considered deprecated. In this case, have you considered using a unix domain socket or FIFO instead of a message queue? Those appear in the filesystem, and can be "cleaned up" when no longer used with tools like rm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文