struct msg_sender {

struct list_head list; struct task_struct* tsk;

list is a list element, and tsk is a pointer to the corresponding task structure. No additional information is required because the sender process goes to sleep during the sys_msgsnd system call — which can also be activated via sys_ipc — used to send the message and automatically repeats the send operation when it is woken.

The data structure to hold the receiver process in the q_receivers list is a little longer. ipc/msg.c struct msg_receiver {

struct list_head r_list;

struct task_struct *r_tsk;

int r_mode;

long r_msgtype;

long r_maxsize;

struct msg_msg *volatile r_msg;

It holds not only a pointer to the corresponding task structure but also the descriptors of the expected message (above all, the message type r_msgtype) and a pointer to a msg_msg instance into which the data are copied if available.

Figure 5-6 illustrates the interplay of the message queue data structures (for the sake of clarity, the list of sleeping senders is not shown).

struct ipc_ids

ID to pointer mapping

struct ipc_ids q_messages q_receivers q_senders struct kern_ipc_perm

^J struct msg_receiver ^J struct task_struct I I struct msg_msg

Figure 5-6: Data structures for System V message queues.

Continue reading here: Shared Memory

Was this article helpful?

0 0