Technical article 100834

Background information on message queues.

OpenServer 5.0.0

Written · Last revised

Problem

I need some background information on message queues for the development of a program.

Solution

Message queues enable communications between processes. There must be sufficient resources available for this type of communication to succeed.

--------------                                 -------------------
|            |         outgoing                |                 |
|            |-------------------------------> |                 |
|            |                                 |                 |
|     A      |                                 |        B        |
|            |         incoming                |                 |
|            |<------------------------------- |                 |
|            |                                 |                 |
--------------                                 -------------------

Process B will, through the correct system calls, tell the kernel that it wants to establish communications to process A. To do this, two channels need to be set up, a talk (outgoing) channel and a listen (incoming channel). Each channel (incoming/outgoing) has its own unique ID number which the kernel keeps track of.

Ideally, if process B is killed or restarted for whatever reason,
it should clean up after itself and request that the message queues
that it has allocated clean up after themselves.  This can be
implemented by a special signal handling routine.  Barring that,
process A should have routines which detect the death of process B
and deallocate accordingly.
Applications are not always coded to clean up after themselves
properly.  In these cases, in order to free up the resources
that have been allocated for the message queues, use the ipcs(ADM)
and ipcrm(ADM) commands.
The ipcs(ADM) commmand is used to provide you with status
information on the queues that have been allocated and what state
they are in.  It will tell you whether there are bytes of unprocessed
information waiting in the queues and what the queue id numbers
are. Of particular use is the "icps -qopt" command.

The ipcrm(ADM) command is used to deallocate the queues that are no longer active.

If the message queues experience hangs or failures, there are three things to examine:

1. Have the high water marks for the message queues been reached? (No single message can have more than MSGMAX bytes in it and no more than MSGMNB bytes per message queue.)

2. Has the overall resource pool been exceeded?

3. Has the application program been coded to properly clean up after itself?

The relevant kernel parameters for message queues in OpenServer 5.0 are:

MSGMAP            512     4       32768
MSGMAX            8192    128     32767
MSGMNB            8192    128     65532
MSGMNI            50      1       1024
MSGSSZ            8       4       4096
MSGTQL            1024    32      16383
MSGSEG            1024    32      32768
Their default, minimum, and maximum values are listed in the mtune
file in /etc/conf/cf.d.  It is important that you _do not_ edit this
file manually; use the configure program or SCOadmin's Hardware/
Kernel manager.

SCO OpenServer 5.0 products allocate MSGSEG * MSGSSZ bytes for message queue memory at kernel initialization time.

UNIX domain sockets (new to OpenServer 5.0 products) can be used for
IPC purposes.  They do use streams for passing messages downstream,
so netstat -m is valid.  This is to be expected as they are only
part of the TCP/IP product and not native IPC mechanisms.
Finally, review the implementation of your application programs
to ensure that they properly deallocate message queues' resources.
Note that no program will get a chance to clean up after itself
if it is killed with a "kill -9" command.  Programs killed in
this way won't get signal SIGCLD unless there'a a parent-child
relationship between them (and this relationship isn't necessary
for IPC to work).

See also

"UNIX Network Programming" by W. Richard Stevens

From the Xinuos technical article database, record 100834. Reproduced with permission. The original is at www.sco.com/ta/100834, which is reachable but blocked from search engines.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.