本文介绍了检查IPC消息队列是否已经存在而不创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何仅检查消息队列是否存在而没有建立消息队列?

How can I just check if a message queue exists or not without making it?

当将msggetO_CREAT | O_EXCL标志一起使用时,如果存在,则调用将失败,返回值-1,但如果不存在,则将创建一个新的消息队列.有什么办法可以检查吗?

When using msgget with O_CREAT | O_EXCL flag, if it exists, the call will fail with return value -1, but if it doesn't, it will then create a new message queue. Is there any way to just check?

推荐答案

ipcs(1)提供有关IPC设施的信息,并且ipcrm(1)可用于从系统中删除IPC对象.

ipcs(1) provides information on the IPC facilities and ipcrm(1) can be used to remove the IPC objects from the system.

列出共享内存段:

ipcs -m

列出消息队列:

ipcs -q

删除使用shmkey创建的共享内存段:

Remove shared memory segment created with shmkey:

ipcrm -M键

删除由shmid标识的共享内存段:

Remove shared memory segment identified by shmid:

ipcrm -m id

ipcrm -m id

删除使用msgkey创建的消息队列:

Remove message queue created with msgkey:

ipcrm -Q键

删除由msgid标识的消息队列:

Remove message queue identified by msgid:

ipcrm -q id

ipcrm -q id

这篇关于检查IPC消息队列是否已经存在而不创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 05:33