Explain the concept of message queues (MQ).
What are the programming steps for MQ?
What are some concerns necessary to consider when defining the message structure?
Give an example of an System V (SV) MQ message structure.
struct mymsg{
long msg_type;
char mytext[512]; /* rest of the message*/
int something_else;
}msg_type used in receptionExplain the process of creation, opening, write, read and destruction for an SV MQ.
Creation
msgget- get a SV MQ identifier - int msgget(key_t key, int msg flg);IPC_PRIVATE. Hinerited by child processes.msgflag - IPC_CREAT. Verify if it exists: msgflag - O_CREAT| O_EXCLOpening
msgflag is NULLWrite
int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
msqid - queue id (returned from msgget)msgflag - IPC_NOWAITRead
ssize_t msgrcv(int msqid, const void *msgp, size_t msgsz, long msgtyp, int msgflg);
msqid - queue id (returned from msgget)msgflag - IPC_NOWAIT, MSG_COPY(does not remove message)Destruction
int msgctl(int msqid, int cmd, struct msqid_ds *buf);
msqidcmd - IPC_RMIDmsqid_ds- NULLDescribe the POSIX MQ message structure.
sysconf(_SC_MQ_PRIO_MAX) - 1 (high)32768 - 1Explain the process of creation, opening, write and read for a POSIX MQ.
Creation
mq_open - open a message queuemqd_t mq_open(const char * name, int oflag, mode_t mode, struct mq_attr * attr);
name - identifieroflags - O_CREAT| O_RDONLY | O_WRONLY | O_RDWRmode - file access modesattr- NULL, struct mq_attr queue _attr;Opening
name- identifier, oflags - O_RDONLY | O_WRONLY | O_RDWRO_CREAT - message queue is assigned to a file queue in /dev/msgque, where the file name is used by other processessmq_unlink - removes a message queue and deletes the filemq_close - closes a message queue descriptor and process can no longer use the queueWrite
int mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned int msg_prio);
mqdes - queue id (returnedf from mq_open)msg_priority - used in mq_receiveRead
ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned int *msg_prio);
mqdes - queue id (returned from mq_open)msg_priority - used in mq_receivemsg_priority - NULL or stores the priority types of the received messageWhat will happen in read/write for empty and full queues?
Empty queue
mq_timedreceive- block some timeFull queue
mq_timedsend - blocks some timeWill lead to errno ETIMEDOUT if timeout is reached.
What are the three ways to limit POSIX MQ?
On the use program - queue_attr.mq_maxmsg and queue_attr.mq_msgsize
Change directly on /etc/security/limits.conf
Values delimited by the OS - /proc/sys/fs/mqueue
Present the characteristics of message queues.