IPC Message Queue Data Structure msgque IPNOUSED Two

  • Slides: 19
Download presentation
IPC Message Queue

IPC Message Queue

Data Structure msgque IP_NOUSED

Data Structure msgque IP_NOUSED

Two channels of Message queue • channel between normal processes – IPC_KERNELD not set

Two channels of Message queue • channel between normal processes – IPC_KERNELD not set • channel between kernel and kernel daemon – kernel daemon:a process which automatically carries out loading and removing of modules. – IPC_KERNELD set

Message • kerneld_msg{ – mtype – id – version header – pid – text[1]}

Message • kerneld_msg{ – mtype – id – version header – pid – text[1]} • msgbuf{ – mtype – mtext[1]}

sys_msgget() • allocate a new message queue, or gain access to an existing message

sys_msgget() • allocate a new message queue, or gain access to an existing message queue. • Flags – IPC_CREAT:a new queue will be created if it is not yet present=>newque() – IPC_EXCL:If IPC_CREAT is set and such a queue exists, the function will return with the error EEXIST.

sys_msgctl() – IPC_INFO:enters special values in the msginfo structure. – IPC_STAT:return current values of

sys_msgctl() – IPC_INFO:enters special values in the msginfo structure. – IPC_STAT:return current values of msqid_ds – IPC_SET:modify values of msqid_ds – IPC_RMID:remove all associated message queue structure

sys_msgsnd() • Send message to message queue. • The process blocks if message length

sys_msgsnd() • Send message to message queue. • The process blocks if message length exceeds the value in msg_qbytes, the permitted maximum. • Blocking can be prevented by setting IPC_NOWAIT.

sys_msgrcv() • receive messages of specified type from message queue. – msgtyp = 0

sys_msgrcv() • receive messages of specified type from message queue. – msgtyp = 0 => get first. – msgtyp > 0 => get first message of matching type. (MSG_EXCEPT not set) – msgtyp < 0 => get message with least type must be < abs(msgtype).

Message queue between kernel & kerneld • IPC_KERNELD set • kerneld_send() – responsible for

Message queue between kernel & kerneld • IPC_KERNELD set • kerneld_send() – responsible for sending messages to the kernel daemon. – KERNELD_WAIT set if we want an answer from kerneld. • kerneld_exit() – called when current process terminated.

IPC PIPE

IPC PIPE

Data Structure

Data Structure

do_pipe • Called by system call pipe • set up a temporary inode and

do_pipe • Called by system call pipe • set up a temporary inode and allocating a page of memory to base. • Return two file descriptors, one for reading, and one for writing.

Open Pipe • pipe_read_open() • pipe_write_open() • pipe_rdwr_open()

Open Pipe • pipe_read_open() • pipe_write_open() • pipe_rdwr_open()

Pipe_Select() • To check whether data can be read from pipe or written to

Pipe_Select() • To check whether data can be read from pipe or written to it. • sel_type: – SEL_IN:for read – SEL_OUT:for write – SEL_EX:for exception

Pipe read operation Blocking Non-Blocking Locked Block calling EAGAIN pipe process Empty Block calling

Pipe read operation Blocking Non-Blocking Locked Block calling EAGAIN pipe process Empty Block calling process EAGAIN if pipe if writing processes present, else return 0 present, else 0 Else Read maximum number of characters up to requested position.

Pipe write operation no reading process locked pipe atomic write possible, but not enough

Pipe write operation no reading process locked pipe atomic write possible, but not enough space in pipe buffer Blocking Non-blocking Send SIGPIPE to writing process and return EPIPE block calling process EAGAIN

Pipe/FIFO write op(cont. ) Buffer space sufficient for atomic write Else Blocking Non-blocking write

Pipe/FIFO write op(cont. ) Buffer space sufficient for atomic write Else Blocking Non-blocking write requested number of bytes to buffer continue blocking until requested number of bytes has been written. as for blocking write. Write maximum Possible number of bytes.

Release pipe • pipe_read_release() • pipe_write_release() • pipe_rdwr_release()

Release pipe • pipe_read_release() • pipe_write_release() • pipe_rdwr_release()

Other operation • pipe_ioctl() – FIONREAD:write the number of bytes within the file not

Other operation • pipe_ioctl() – FIONREAD:write the number of bytes within the file not yet read to address arg. • pipe_lseek():invalid.