MSGGET(3L)

NAME
msgget - get message queue

SYNOPSIS
#include <message.h>

long msgget (key, msgflg)
long key;
int msgflg;

DESCRIPTION
Msgget returns the message queue identifier associated with key.

A message queue identifier and associated message queue and data structure are created for key if one of the following is true:

    Key is equal to IPC_PRIVATE.

    Key does not already have a message queue identifier associated with it, and (msgflg & IPC_CREAT) is ``true''.

Upon creation, the data structure associated with the new message queue identifier is initialized as follows:

    Msg_qnum, msg_curbytes, msg_list, msg_lspid, msg_lrpid, msg_stime, and msg_rtime are set equal to 0.

    Msg_ctime is set equal to the current time (realtime).

    Msg_qbytes is set equal to MAX_QBYTES.

    State is set to (msgflg & NO_SAVE).

    Cid is set to the calling process's id (P).

    Name is set to key.

If state is ``true'', the message queue will be deleted when the process cid is deleted.

Msgget will fail if one or more of the following are true:

    A message queue identifier does not exist for key and (msgflg & IPC_CREAT) is ``false''.

    A message queue identifier is to be created but there isn't enough memory.

    A message queue identifier exists for key but ( [msgflg & IPC_CREAT] && [msgflg & IPC_EXCL] ) is ``true''.

Each message queue identifier that msgget returns is added to a list maintained for the application. This list defines which message queues constitute the MSG resource when using the wait(MSG) and own(MSG) functions.

  Return Value
Upon successful completion, a non-negative long, namely a message queue identifier (pointer to msqid_ds structure), is returned. Otherwise, a value of -1 is returned.

SEE ALSO
msgctl(3L), msgop(3L), realtime(3R), resources(3R), structures(3R).