Check if a IPC message queue already exists without creating it

南笙酒味 提交于 2020-01-25 21:13:12

问题


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

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?


回答1:


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

List shared memory segments:

ipcs -m

List message queues:

ipcs -q

Remove shared memory segment created with shmkey:

ipcrm -M key

Remove shared memory segment identified by shmid:

ipcrm -m id

Remove message queue created with msgkey:

ipcrm -Q key

Remove message queue identified by msgid:

ipcrm -q id



来源:https://stackoverflow.com/questions/40889356/check-if-a-ipc-message-queue-already-exists-without-creating-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!