#include <sys/msg.h> #include <sys/stat.h> int msgget(key_t key, int msgflg);
The msgget() function either creates a new message queue or returns the message queue identifier associated with the key parameter for an existing message queue. A new message queue is created if one of the following is true:
The system maintains status information about a message queue which can be retrieved with the msgctl() function. When a new message queue is created, the system initializes the members of the msqid_ds structure as follows:
Authorization Required for msgget()
Object Referred to | Authority Required | errno |
---|---|---|
Message queue to be created | None | None |
Existing message queue to be accessed | See Note | EACCES |
Note: If the thread is accessing an existing message queue, the mode specified in the last 9 bits of msgflg must be a subset of the mode of the existing message queue.
value | msgget() was successful. The value returned is the message queue identifier associated with the key parameter. |
-1 | msgget() was not successful. The errno variable is set to indicate the error. |
If msgget() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
Permission denied.
An attempt was made to access an object in a way forbidden by its object access permissions.
The thread does not have access to the specified file, directory, component, or path.
A message queue identifier exists for the parameter key, but permissions specified in the low-order 9 bits of semflg are not a subset of the current permissions.
A damaged object was encountered.
A referenced object is damaged. The object cannot be used.
The message queue has been damaged by a previous message queue operation.
File exists.
The file specified already exists and the specified operation requires that it not exist.
The named file, directory, or path already exists.
A message queue identifier exists for the key parameter and both the IPC_CREAT and IPC_EXCL flags are set in the msgflg parameter.
No such path or directory.
The directory or a component of the path name specified does not exist.
A named file or directory does not exist or is an empty string.
A message queue identifier does not exist for the key parameter, and the IPC_CREAT flag is not set in the msgflg parameter.
No space available.
The requested operations required additional space on the device and there is no space left. This could also be caused by exceeding the user profile storage limit when creating or transferring ownership of an object.
Insufficient space remains to hold the intended file, directory, or link.
A message queue identifier cannot be created because the system limit on the maximum number of allowed message queue identifiers would be exceeded.
Unknown system state.
The operation failed because of an unknown system state. See any messages in the job log and correct any errors that are indicated, then retry the operation.
None.
See Code disclaimer information for information pertaining to code examples.
The following example creates a message queue:
#include <sys/msg.h> #include <sys/stat.h> main() { int msqid; msqid = msgget(IPC_PRIVATE, IPC_CREAT | S_IRUSR | S_IWUSR); }
Top | UNIX-Type APIs | APIs by category |