msgget(2) — System Calls
NAME
msgget − Returns (and possibly creates) the ID for a message queue
SYNOPSIS
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h> int msgget (
key_t key,
int msgflg );
PARAMETERS
keySpecifies the key that identifies the message queue. The value for the key parameter can be IPC_PRIVATE or a random number other than zero (0). If the value of key is IPC_PRIVATE, it can be used to assure the return of a new, unused message queue ID.
msgflgSpecifies creation flags. Possible values are:
IPC_CREAT
If the key specified does not exist, the msgget function creates a message queue ID using the specified key.
If the specified key does exist, and IPC_EXCL is not set, the message queue ID for the key is returned.
If the specified key does exist and IPC_EXCL is set, the msgget function fails and returns an error.
IPC_EXCLIf the specified key already exists, the msgget function fails and returns an error notification.
The low-order nine bits of msg_perm.mode are set equal to the low-order nine bits of msgflg.
DESCRIPTION
The msgget function returns (and possibly creates) the message queue ID for the message queue identified by the key parameter. If IPC_PRIVATE is used for key, the msgget function returns the ID for a private (that is, newly created) message queue. The msgflg parameter supplies creation options for the msgget function. If the key parameter does not already exist, IPC_CREAT instructs the msgget function to create a new message queue for the key and return the kernel-assigned ID for the message queue.
After creating a new message queue ID, the msgget function initializes the msqid_ds structure associated with the ID as follows:
•The msg_perm.cuid and msg_perm.uid members are set equal to the effective user ID of the calling process.
•The msg_perm.cgid and msg_perm.gid members are set equal to the effective group ID of the calling process.
•The low-order nine bits of the msg_perm.mode member are set equal to the low-order nine bits of msgflg.
•The msg_qnum, msg_lspid, msg_lrpid, msg_stime, and msg_rtime members are all set equal to zero.
•The msg_ctime member is set equal to the current time.
•The msg_qbytes member is set equal to the system limit.
RETURN VALUE
Upon successful completion, a message queue identifier is returned. If the msgget function fails, a value of -1 is returned and errno is set to indicate the error.
ERRORS
If the msgget function fails, errno may be set to one of the following values:
[EACCES]A message queue identifier exists for the key parameter but operation permission, which is specified by the low-order nine bits of the msgflg parameter, is not granted.
[ENOENT]A message queue identifier does not exist for the key parameter and the IPC_CREAT value is not set.
[ENOSPC]A message queue identifier can be created, but the system-imposed limit on the maximum number of allowed message queue identifiers has been exceeded.
[EEXIST]A message queue identifier exists for the key parameter, and both IPC_CREAT and IPC_EXCL are set.
RELATED INFORMATION
Functions: msgctl(2), msgrcv(2), msgsnd(2), table(2).
Data Structures: msqid_ds(4).