Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

msgget - get message queue

&pagelevel(4)&pagelevel

Syntax

#include <sys/msg.h>

int msgget(key_t key, int msgflg); 

Description

msgget() returns the message queue identifier associated with key.
A message queue identifier, associated message queue, and data structure (see sys/msg.h) are created for key if one of the following is true:

  • key is IPC_PRIVATE.

  • key does not already have a message queue identifier associated with it, and (msgflg & IPC_CREAT) is non-zero.

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

  • 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.

  • The low-order 9 bits of msg_perm.mode are set equal to the low-order 9 bits of msgflg.

  • msg_qnum, msg_lspid, msg_lrpid, msg_stime and msg_rtime are set equal to 0.

  • msg_ctime is set equal to the current time.

  • msg_qbytes is set equal to the system limit.

Return val.

Non-negative integer (message queue identifier)


if successful.

-1

if an error occurs. errno is set to indicate the error.

Errors

msgget() will fail if: 

 

EACCES

A message queue identifier exists for the argument key, but the access permissions specified by the low-order 9 bits of msgflg are not granted (see section “Interprocess communication”).

 

EEXIST

A message queue identifier exists for the argument key, but the value of ((msgflg & IPC_CREAT) && (msgflg & IPC_EXCL)) is non-zero.

 

ENOENT

A message queue identifier exists for the argument key and (msgflg & IPC_CREAT) is 0.

 

ENOSPC

A message queue identifier is to be created, but the system-imposed limit on the maximum number of allowed message queue identifiers systemwide would be exceeded.

Notes

The IEEE 1003.4 Standards Committee is developing alternative interfaces for interprocess communication. Application developers who need to use interprocess communication (IPC) should design their applications so that modules using the IPC routines described here can be easily modified at a later date.

See also

msgctl(), msgrcv(), msgsnd(), sys/msg.h, section “Interprocess communication”.