I'm writing some code to replace TCP sockets with POSIX message queues. Sometimes the program will crash (still in development) and the queues that were created are not deleted (did not execute: mq_close()
+ mq_unlink()
). This causes issues when I run the code again.
Is there a way to delete/remove these queues using the command line? I tried using: ipcs -q
. This failed to list any queues.
I tried: lsof | grep queue-name
. They did show up here.
Ideally, I'd like to use: ipcrm
.
POSIX message queues are a means by which processes exchange data in the form of messages to accomplish their tasks. They enable processes to synchronise their reads and writes to speed up processes. POSIX message queues are distinct from System V messages.
System V IPC is older and POSIX IPC is newer. However there are some differences for some aspects. Not always Posix is better than System V. The semaphores, queues and shared memory for Posix have Ascii string names, while under System V these are given with integer number.
Use the Unix command ipcs to get a list of defined message queues, then use the command ipcrm to delete the queue. Write a program to do it for you.
To send a message, a component called a producer adds a message to the queue. The message is stored on the queue until another component called a consumer retrieves the message and does something with it. Many producers and consumers can use the queue, but each message is processed only once, by a single consumer.
POSIX IPC objects are implemented as files in virtual file systems. These files can be listed and removed with ls and rm. To do this with POSIX message queues, we must mount the message queue file system using the following commands:
$ su
Password:
# mkdir /dev/mqueue
# mount -t mqueue none /dev/mqueue
# exit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With