Article Title: Practical Tips: detailed explanation of Msgget function calls in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Function Description:
Gets the ID of the Message Queue associated with a key. There are two scenarios in which a message queue is created:
1. If the key value is IPC_PRIVATE.
2. Alternatively, the key value is not IPC_PRIVATE, and the message queue corresponding to the key does not exist, and IPC_CREAT is specified in the flag.
If a new message queue is created, the msqid_ds data structure associated with it is initialized as follows:
Msg_perm.cuid and msg_perm.uid are valid user IDs of callers;
Msg_perm.cgid and msg_perm.gid are valid user group logos of callers;
Msg_perm.mode: The minimum nine digits are set to the lowest nine digits of msgflg;
Msg_qnum, msg_lspid, msg_lrpid, msg_stime, and msg_rtime are set to 0;
Msg_ctime is set to the current time;
Msg_qbytes is set to MSGMNB.
Usage:
# Include
# Include
# Include
Int msgget (key_t key, int msgflg );
Parameters:
Key: The key associated with the message queue.
Msgflg: indicates the establishment and access permissions of message queues.
Return description:
If the message queue is successfully executed, the Message Queue id value is returned. -1 is returned for failure, and errno is set to one of the following values
EACCES: the specified message queue already exists, but the calling process does not have the permission to access it and does not have the CAP_IPC_OWNER permission.
EEXIST: The Message Queue specified by the key already exists, while IPC_CREAT and IPC_EXCL are both specified in msgflg.
ENOENT: The Message Queue specified by the key does not exist. The IPC_CREAT flag is not specified in msgflg.
ENOMEM: A Message Queue needs to be created, but the memory is insufficient.
ENOSPC: A Message Queue needs to be created, but the system limit has been reached.