Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

migrated from serverfault.com Apr 2 '13 at 7:31

This question came from our site for professional system and network administrators.

2 Answers

up vote 1 down vote accepted

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 */
       };
share|improve this answer
add comment

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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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