Initializing a Message Queue
msgget
()
initializes a new message queue. It can also
return the message queue ID (msqid
) of the
queue corresponding to the key argument. The value passed as the
msgflg
argument must be an octal integer with
settings for the queue's permissions and control flags.
The MSGMNI
kernel configuration option
determines the maximum number of unique message queues that
the kernel supports. msgget
()
fails when
this limit is exceeded. For more information, see the
msgget
(2) man page.
The following code illustrates msgget
().
#include <sys/ipc.h> #include <sys/msg.h> ... key_t key; /* key to be passed to msgget() */ int msgflg, /* msgflg to be passed to msgget() */ msqid; /* return value from msgget() */ ... key = ... msgflg = ... if ((msqid = msgget(key, msgflg)) == -1) { perror("msgget: msgget failed"); exit(1); } else (void) fprintf(stderr, "msgget succeeded"); ...