Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Posix message queues and the command line?

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.

like image 688
jski Avatar asked Jun 11 '15 15:06

jski


People also ask

What is a POSIX message queue?

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.

What is difference between System V and POSIX?

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.

How do I see message queue in Linux?

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.

How do you use message queues?

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.


1 Answers

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
like image 55
jski Avatar answered Oct 30 '22 17:10

jski