PDA

View Full Version : Message Queue limit for MAC OS X




pankaj.acs
Oct 5, 2010, 12:30 PM
Hello all,

We have a application where two processes communicate via IPC.
We are currently using Message Queue for this communication.

The problem that we are facing is that the Max message that we are able to send through Message Q is only 2048 bytes! :(

As soon as we send data more than 2048 bytes, msgsend returns -1 with error code: 22 [Invalid arguments].

We tried increasing the Message Q size using msgctl system call, but to no avail.
Even though msgctl for msgsize > 2048 returns success, the message Q size remains 2048 only.

Sample program that i wrote to increase the Message Q size is as follows:

**********************************************
msgid = msgget((key_t)1234, 0666 | IPC_CREAT);
if(-1==msgctl(msgid,IPC_STAT,&queue_ds))
{
printf("\nFailure in msgctl() 1");
}

printf("Queue size: %d", (int) queue_ds.msg_qbytes);

/* Increase Queue size */
queue_ds.msg_qbytes = 5000;

if(-1==msgctl(msgid,IPC_SET,&queue_ds))
{
printf("\nFailure in msgctl()");
}
else
{
printf("Queue size updated to: %d", (int) queue_ds.msg_qbytes);
}

if(-1==msgctl(msgid,IPC_STAT,&queue_ds))
{
printf("\nFailure in msgctl() 2");
}
printf("Modified Queue size: %d", (int) queue_ds.msg_qbytes);

*************************************************

Output:
Queue size: 2048
Queue size updated to: 5000
Modified Queue size: 2048

Any idea why we are not able to increase the Message Q size?
Is this a limitation on Mac OS X?

Appreciate any help/pointers in this regard.

Cheers!



robbieduncan
Oct 5, 2010, 01:05 PM
From http://osxfaq.com/man/2/msgctl.ws

"IPC_SET ... This operation can only be executed by the super-user"

Are your programs executing as the super-user (running as root or effectively the same)?

pankaj.acs
Oct 5, 2010, 01:33 PM
Yes, i executed the msgctl using super-user only.
Otherwise, I believe msgctl would have failed.

However, am eager to know if anyone has actually tried changing the Message Q size in Mac OS X?
I mean, is it even possible without recompiling the kernel.

chown33
Oct 5, 2010, 02:16 PM
Post complete compilable runnable code, not just a code fragment.

Why are you using msgq at all? My impression is that it's not designed or intended for large amounts of data. If you have multiple processes, especially unprivileged ones, sending large amounts of data, you're better off using either Unix-domain sockets or IP-domain sockets confined to localhost (the lo0 loopback interface).