John B. Matthews
8/11/2008 5:46:00 PM
On 10 Aug 2008 at 23:27, Ahmad Jalil Qarshi wrote:
> I have developed an application in C on IBM AIX 5.2. Its using
> multiple Message Queues to share data between different processes. I
> am using following functions to send/receive messages into/from
> message queues:
>
> int msgget(key_t, int);
> ssize_t msgrcv(int, void *, size_t, long int, int);
> int msgsnd(int, const void *, size_t, int);
>
> Now I want to calculate number of messages in each message queue at a
> specific time. So which function should I use? There is a function
> named "mq_getattr" to get queue attributes. Can this help out?
No, but there's a function called msgctl() that you can use for that.
int msgctl(int msqid, int cmd, struct msqid_ds *buf);
If you call this function with IPC_STAT as the cmd argument, this will
fill out the struct pointed to by buf with various bits of information
from the kernel struct associated to the message queue. Check the
documentation for your system to find out what this information consists
of, but in particular POSIX guarantees the existence of a buf->msg_qnum
field of type msgqnum_t, which contains the current number of messages
in the queue.