I am trying to determine what the maximum number of messages a queue can hold is and have written this to do so:
1 2 3 4 5 6 7 8 9 10
struct parent_child_buffer receivedData = { 0, 0, 0.0, 0.0 }; //Create container for parent-child communication
receivedData.grossWeight = airplanePointer->getGrossWeight();
struct msqid_ds receivedDataControl; //Create a structre to store message queue information in
if (msgctl(msqid, IPC_STAT, (struct msqid_ds *) &receivedDataControl) == -1) //Copy the control structure
{
perror("Error when creating copy of msquid_ds structure"); //Report error if there was one
return 0;
}
int receivedDataSize = sizeof(receivedData);
int numberMessagesMax = (receivedDataControl.msg_qbytes/receivedDataSize) - 1;
The problem is it comes up with 511 being the maximum number but the queue regualarly has 2000+ messages. What am I missing here?
As of at least early 2.6 kernels there was/is a bug in the kernel where the kernel checks the message count against the number of bytes in the queue, not the number of messages in the queue.
There is a parameter you can set in the /proc filesystem. Something like
/proc/ssysvipc/msgmax (sorry, I'm not running linux right now). There are
three parameters IIRC. One is for the maximum number of bytes that can be put in the queue, and a second is for the maximum number of messages that can be in the queue. The idea was that your queue would be limited to either the number of bytes or number of messages, whichever comes first, but the kernel checks the current number of messages against the "max bytes" parameter instead of "max messages" so it's basically only limited by the number of bytes in the queue.
There is nothing you can do at the application level to fix that short of making a kernel change.