We can check the details of system V message queue with the help of ipcscommand. Is there any command to check POSIX message queue in Linux?


There is no command I know of but there exists a libc function call which can get the statistics:

man 3 mq_getattr

   mq_getattr() returns an mq_attr structure  in  the  buffer  pointed  by
   attr.  This structure is defined as:

       struct mq_attr {
           long mq_flags;       /* Flags: 0 or O_NONBLOCK */
           long mq_maxmsg;      /* Max. # of messages on queue */
           long mq_msgsize;     /* Max. message size (bytes) */
           long mq_curmsgs;     /* # of messages currently in queue */
| improve this answer | |

If you're lucky enough to use HP-UX, the command pipcs (PDF) performs the POSIX equivalent to the SysV IPC ipcs command. Sadly, it has never appeared for other OS's. The current (March 2013) util-linux package which provides ipcs barely mentions POSIX mqueues.

If you have mqueue mounted on /dev/mqueue, what is supported is simply reading the queue as a file:

user@linux $ cat /dev/mqueue/myQ
QSIZE:0          NOTIFY:0     SIGNO:0     NOTIFY_PID:0 

The QSIZE is unfortunately the size in bytes, not messages; on Linux there is (as yet) no message count field -- unlike FreeBSD which provides a CURMSG value:

user@freebsd $ cat /mnt/mqueue/myQ
QSIZE:0          MAXMSG:32         CURMSG:0          MSGSIZE:1024   

So the answer should be "mount the mqueue FS and use cat", but it's not :(

(Mounting the mqueue FS is not a prerequisite for using the MQ API, it just lets you do some "everything is a file" stuff.)

If you really need to monitor queues, the book The Linux Programming Interface has the C source code for various CLI tools to create, inspect and use message queues. Happily chapter 52 of the book which covers this topic is currently available free to download. See pmsg_getattr.c.

The canonical reference code from Stephen's Unix Network Programming (Vol 2) 2nd Ed. (1999) is available here, it provides amongst other things mqgetattr which will do the job too (though you'll likely need to massage a couple of lines in the top level config.h, the #define's for various uint types conflict with contemporary Unix system headers).

There are also Ruby, Perl and TCL modules for this, the Ruby one comes with a posix-mq-rb CLI tool.

| improve this answer | |
  • I using ubuntu system.. – sujin Apr 15 '13 at 18:18

$ ipcs -q will provide message queue stats from the command line.

$ ipcs -m will provide shared memory stats from the command line.

$ ipcs will provide all ipc mechanism stats.

| improve this answer | |
  • 8
    ipcs is not for POSIX1 message queues – whoan Nov 1 '16 at 5:46
  • 2
    ipcs is used for System V message queues and not for POSIX message queues – Yerke Jul 7 '18 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.