消息队列使用共享内存/信号量,如何检查是否没有连接到队列?
typedef struct
{
char data[MESSAGE_SIZE];
} MESSAGE;
typedef struct
{
sem_t sem_send;
sem_t sem_receive;
MESSAGE messages[];
} MQ;
目前正在处理消息队列,我想删除队列,但要这样做 我需要销毁信号量(sem_destroy)然后shm_unlink 但是我需要确保目前没有连接到队列的过程
如何实现?
typedef struct
{
char data[MESSAGE_SIZE];
} MESSAGE;
typedef struct
{
sem_t sem_send;
sem_t sem_receive;
MESSAGE messages[];
} MQ;
Currently working on message queue, I want to delete the queue but in order to do so
I need to destroy the semaphore (sem_destroy ) then shm_unlink
but I need to be sure that there is no process currently connected to the queue
How can I achieve this please ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您想要的是UNIX插座而不是消息队列。检查
MAN 7 UNIX
,有一个如何使用它的示例。使用UNIX插座,您会得到:消息队列没有任何有关连接到它的过程的信息。消息队列可以存在,而无需附加任何过程。
Maybe what you want is a UNIX socket instead of a message queue. Check
man 7 unix
, there's an example of how to use it. With UNIX sockets you get:The message queues don't tell anything about other processes connecting to it. Message queues can exist without any process attach to it.