Posix 消息队列创建给出“无法分配内存”执行几次后出错!
我创建了 4 个子进程,并通过一对消息队列在它们之间进行通信。我成功地做到了这一点,但在执行几次后它给出了错误“无法分配内存”。我猜这是由于没有正确删除现有队列造成的。我是否需要在程序结束之前关闭或取消链接每个子进程执行,或者在父进程中关闭它们就足够了。或者有什么方法可以关闭 - 使用某些命令在命令行(shell)上取消链接它们。任何建议!我需要重新启动系统作为解决方案,但这当然需要时间。
感谢您的帮助!
I create 4 child process and communicate between by a message queue for a couple. I successes to do that bur after a couple of execution it gives error "Cannot allocate memory". I guess it is caused by not deleting the existing queues properly. Do i need to close or unlink in each child process execution before end of the program or it is enough to close them in the parent process. OR is there any way to close - unlink these on the command line (shell) with some commands. Any suggestions! I need to restart the system as a solution but it takes time of course.
Thanks for help!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果按照
man mq_overview
中的说明挂载 MQ 虚拟文件系统,则可以使用 C API 或使用 shell 取消链接 POSIX 消息队列(这将为您提供“磁盘”上的“目录”(当然不是这样),然后您可以使用 ls 和 rm 等命令。手册页还讨论了其他人创建新队列时阻止您创建新队列的相关限制 。没有被正确丢弃。
You can unlink POSIX messages queues either using the C API or using the shell if you mount the MQ virtual filesystem as per the instructions in
man mq_overview
(which will give you a "directory" on "disk" (not really, of course), where you can then use commands likels
andrm
.The man pages also discuss the relevant limits that are blocking you from creating new queues when others have not been properly discarded.
是的,您需要在每个子进程中调用 mq_close() ,否则队列将不会被删除。 mq_unlink() 的帮助说,
http://pubs.opengroup.org/onlinepubs/007908799/xsh/mq_unlink.html
Yes, you need to call mq_close() in each child process or the queue won't be removed. The help for mq_unlink() says,
http://pubs.opengroup.org/onlinepubs/007908799/xsh/mq_unlink.html