MSGGET(2) System Calls Manual MSGGET(2)
msgget - get message queue
int msgget(key, msgflg)
msgget() returns the message queue identifier associated with key.
A message queue identifier and associated message queue and data struc-
ture (see intro(2)) are created for key() if one of the following is
o key is equal to IPC_PRIVATE.
o 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:
o msg_perm.cuid, msg_perm.uid, msg_perm.cgid, and msg_perm.gid are set
equal to the effective user ID and effective group ID, respectively,
of the calling process.
o The low-order 9 bits of msg_perm.mode are set equal to the low-order
9 bits of msgflg.
o msg_qnum, msg_lspid, msg_lrpid, msg_stime, and msg_rtime are set
equal to 0.
o msg_ctime is set equal to the current time.
o msg_qbytes is set equal to the system-wide standard value of the
maximum number of bytes allowed on a message queue.
A message queue identifier (msqid) is a unique positive integer created
by a msgget(2) system call. Each msqid has a message queue and a data
structure associated with it. The data structure is referred to as
msqid_ds() and contains the following members:
struct ipc_perm msg_perm; /* operation permission struct */
ushort msg_qnum; /* number of msgs on q */
ushort msg_qbytes; /* max number of bytes on q */
ushort msg_lspid; /* pid of last msgsnd operation */
ushort msg_lrpid; /* pid of last msgrcv operation */
time_t msg_stime; /* last msgsnd time */
time_t msg_rtime; /* last msgrcv time */
time_t msg_ctime; /* last change time */
/* Times measured in secs since */
/* 00:00:00 GMT, Jan. 1, 1970 */
msg_perm() is an ipc_perm structure that specifies the message opera-
tion permission (see below). This structure includes the following
ushort cuid; /* creator user id */
ushort cgid; /* creator group id */
ushort uid; /* user id */
ushort gid; /* group id */
ushort mode; /* r/w permission */
msg_qnum is the number of messages currently on the queue. msg_qbytes
is the maximum number of bytes allowed on the queue. msg_lspid is the
process ID of the last process that performed a msgsnd operation.
msg_lrpid is the process ID of the last process that performed a msgrcv
operation. msg_stime is the time of the last msgsnd operation,
msg_rtime is the time of the last msgrcv operation, and msg_ctime is
the time of the last msgctl(2) operation that changed a member of the
msgget() returns A non-negative message queue identifier on success.
On failure, it returns -1 and sets errno to indicate the error.
EACCES A message queue identifier exists for key, but operation
permission (see intro(2)) as specified by the low-order
9 bits of msgflg would not be granted.
EEXIST A message queue identifier exists for key() but (
(msgflg & IPC_CREAT) & (msgflg & IPC_EXCL)) is ``true''.
ENOENT A message queue identifier does not exist for key() and
(msgflg & IPC_CREAT) is ``false''.
ENOSPC A message queue identifier is to be created but the sys-
tem-imposed limit on the maximum number of allowed mes-
sage queue identifiers system wide would be exceeded.
intro(2), msgctl(2), msgop(2)
21 January 1990 MSGGET(2)