Help needed with System V message queues

stephen.a.rago sar0 at cbnewsl.att.com
Thu Aug 9 00:30:26 AEST 1990


In article <1169 at compel.UUCP>, her at compel.UUCP (Helge Egelund Rasmussen) writes:
> 
> I want to send long messages via a System V message queue. This is done by 
> the msgsnd system call. Because of this, I need to determine the max length
> of a single message. 
> 
> The 'msgctl' call can return a value called 'msg_qbytes' which is described
> as 'the maximum number of bytes allowed on the queue'. This value is 4096 on
> our system.
> 
> However, if I send a message with this length, I get return status -1 and 
> errno = EINVAL, indicating that the message size is too big.
> My program works with a max length of 2000 bytes.
> 
> I've found a tunable parameter called MSGMAX (current value 2048), which may
> be the actual max message size.
> 
> The funny thing is that the max value that I can give MSGMAX is 8192, which 
> is greater than 'msg_qbytes' (4096). Does this mean that it is possible to
> send messages that are bigger than the message queue???

No.  msg_qbytes, as you've stated, is the maximum number of bytes on the
queue.  If you try to send a message larger than the number of bytes the
queue can hold, then it will either
 (a) fail if IPC_NOWAIT is set, or
 (b) sleep forever because the queue will never be able to accommodate
	the message.
> 
> I'm using Interactive Unix v.3.2.
> 
> Questions:
>    - Is MSGMAX the size of the biggest message I can send?

Yes.

>    - If so, what on earth do I use 'msg_qbytes' for?

Consider wanting to send multiple messages to a queue.
The reader may not be reading messages at the moment, so the
queue holds onto them.  This is better for most applications
than making all senders block until the reader gets their message.

Strictly speaking, msg_qbytes (MSGMNB) should be >= MSGMAX,
otherwise there arguably has been a configuration error on the
part of the system administrator.

>    - How do I get the current value of MSGMAX in my program?

If you mean "how do I find out what the value of MSGMAX is on my system
from inside my program?", there is no system call interface that returns
the value, but you can assume that it is less than or equal to msg_qbytes.
You might try creating a dummy message queue, and iteratively placing
a message on the queue and then removing it, increasing the size each
iteration until either EINVAL is returned, or you reach a size of msg_qbytes.
Or you can try to parse the /etc/master.d/msg master file.  The only
problem with that is that what's in the master file may not match the
/unix you are running.

Steve Rago
sar at attunix.att.com



More information about the Comp.unix.wizards mailing list