内容简介
#include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> |
int msgget(key_t%uA0key,%uA0int%uA0msgflg)
描述
The%uA0msgget() system call returns the message queue identifier associated with the value of the%uA0key%uA0argument. A new message queue is created if%uA0key%uA0has the valueIPC_PRIVATE%uA0or%uA0key%uA0isn’t%uA0IPC_PRIVATE, no message queue with the given key%uA0keyexists, and%uA0IPC_CREAT%uA0is specified in%uA0msgflg.If%uA0msgflg%uA0specifies both%uA0IPC_CREAT%uA0and%uA0IPC_EXCL%uA0and a message queue already exists for%uA0key, then%uA0msgget() fails with%uA0errno%uA0set to%uA0EEXIST. (This is analogous to the effect of the combination%uA0O_CREAT | O_EXCL%uA0for%uA0open(2).)
Upon creation, the least significant bits of the argument%uA0msgflgꃞfine the permissions of the message queue. These permission bits have the same format and semantics as the permissions specified for the%uA0mode%uA0argument of%uA0open(2). (The execute permissions are not used.)
If a new message queue is created, then its associated data structure%uA0msqid_ds%uA0(seemsgctl(2)) is initialised as follows:
标签 | 描述 |
---|---|
%uA0 | msg_perm.cuid%uA0and%uA0msg_perm.uid%uA0are set to the effective user ID of the calling process. |
%uA0 | msg_perm.cgid%uA0and%uA0msg_perm.gid%uA0are set to the effective group ID of the calling process. |
%uA0 | The least significant 9 bits of%uA0msg_perm.mode%uA0are set to the least significant 9 bits of%uA0msgflg. |
%uA0 | msg_qnum,%uA0msg_lspid,%uA0msg_lrpid,%uA0msg_stime%uA0and%uA0msg_rtime%uA0are set to 0. |
%uA0 | msg_ctime%uA0is set to the current time. |
%uA0 | msg_qbytes%uA0is set to the system limit%uA0MSGMNB. |
返回值
If successful, the return value will be the message queue identifier (a nonnegative integer), otherwise -1 with%uA0errno%uA0indicating the error.错误
On failure,%uA0errno%uA0is set to one of the following values:标签 | 描述 |
---|---|
EACCES | A message queue exists for%uA0key, but the calling process does not have permission to access the queue, and does not have the%uA0CAP_IPC_OWNERꃊpability. |
EEXIST | A message queue exists for%uA0key%uA0and%uA0msgflg%uA0specified bothIPC_CREAT%uA0and%uA0IPC_EXCL. |
ENOENT | No message queue exists for%uA0key%uA0and%uA0msgflg%uA0did not specifyIPC_CREAT. |
ENOMEM | A message queue has to be created but the system does not have enough memory for the new data structure. |
ENOSPC | A message queue has to be created but the system limit for the maximum number of message queues (MSGMNI) would be exceeded. |
注意
IPC_PRIVATE%uA0isn’t a flag field but a%uA0key_t%uA0type. If this special value is used for%uA0key, the system call ignores everything but the least significant 9 bits of%uA0msgflg%uA0and creates a new message queue (on success).The following is a system limit on message queue resources affecting a%uA0msgget() call:
标签 | 描述 |
---|---|
MSGMNI | System wide maximum number of message queues: policy dependent (on Linux, this limit can be read and modified via/proc/sys/kernel/msgmni). |