如何窥视到一个Linux(POSIX)消息队列不删除的项目? [英] How to peek into a Linux (POSIX) message queue without removing an item?

查看:445
本文介绍了如何窥视到一个Linux(POSIX)消息队列不删除的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要窥视到一个消息队列不删除它们。我会继续和删除,只有当它符合一定条件的消息队列项。如何做到这一点?以下是我知道的API - 但似乎没有偷看支持

I need to peek into a message queue without removing them. I will go ahead and remove the message queue item only if it complies to certain criteria. How to do this? Following are the APIs I know — but none seems support peeking.


  • mq_close() - 关闭一个消息队列

  • mq_close() — close a message queue

mq_getattr() - 得到一个消息队列的当前属性

mq_getattr() — get the current attributes of a message queue

mq_notify() - 当队列变得非空通知调用进程

mq_notify() — notify the calling process when the queue becomes nonempty

mq_open() - 打开或创建一个消息队列

mq_open() — open or create a message queue

则mq_receive() - 从队列中收到消息

mq_receive() — receive a message from a queue

则mq_se​​nd() - 把一个消息到消息队列

mq_send() — put a message into a message queue

mq_se​​tattr() - 设置标志的消息队列

mq_setattr() — set the flags for a message queue

mq_unlink() - 取消链接(即删除)一个消息队列

mq_unlink() — unlink (i.e. delete) a message queue

有没有办法在消息偷看而不删除它?

Is there a way to peek at a message without removing it?

推荐答案

偷看可能是一个消息队列一个坏主意,因为像sehe指出,竞争条件的危险。只是假设你已经偷看的消息;因为你不能锁队列中,您将无法可靠地恢复你已经偷看了相同的消息。如果从同一个队列接收相互排斥的消息的两个过程,你应该考虑这些信息分成两个队列,为设计和竞争状态稳定清晰。

Peeking is probably a bad idea for a message queue because, like sehe noted, the danger of race conditions. Just assume you have peeked a message; since you cannot lock the queue, you will be unable to reliably retrieve the same message you have peeked. If you have two processes receiving mutually exclusive messages from the same queue, you should be thinking about separating these messages into two queues, for clarity of design and race condition stability.

答作了简短:一个PEEK是非常不可能的,因为它需要明确的锁定语义执行它稳定

Answer made short: A peek is very unlikely because it would need explicit locking semantics to carry it out stably.

这篇关于如何窥视到一个Linux(POSIX)消息队列不删除的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆