The function returns the message queue identifier associated with the value of the key argument. A new message queue is created if key has the value IPC_PRIVATE or key isnt IPC_PRIVATE, no message queue with the given key key exists, and IPC_CREAT is asserted in msgflg (i.e., msgflg&IPC_CREAT is nonzero). The presence in msgflg of the fields IPC_CREAT and IPC_EXCL plays the same role, with respect to the existence of the message queue, as the presence of O_CREAT and O_EXCL in the mode argument of the open(2) system call: i.e. the msgget function fails if msgflg asserts both IPC_CREAT and IPC_EXCL and a message queue already exists for key.
Upon creation, the lower 9 bits of the argument msgflg define the access permissions of the message queue. These permission bits have the same format and semantics as the access permissions parameter in open(2) or creat(2) system calls. (The execute permissions are not used.)
If a new message queue is created, the system call initializes the system message queue data structure msqid_ds as follows: