This is used for creating a new message queue, and for accessing an existing queue that is related to the specified key. If this is executed successfully, the function returns the identifier of the message queue:
int msgget(key_t key, int flag);
Here, we have to address the following:
- key: This is a unique key value that is retrieved by invoking the ftok function.
- flag: This can be any of the following constants:
- IPC_CREAT: Creates the message queue if it doesn't already exist and returns the message queue identifier for the newly created message queue. If the message queue already exists with the supplied key value, it returns its identifier.
- IPC_EXCL: If both IPC_CREAT and IPC_EXCL are specified and the message queue does not exist, then it is created. However, if it already exists, then the function will fail.