200 likes | 256 Views
IPC. Message Queue. Data Structure. msgque. IP_NOUSED. 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.
E N D
IPC Message Queue
Data Structure msgque IP_NOUSED
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
kerneld_msg{ mtype id version pid text[1]} msgbuf{ mtype mtext[1]} Message header
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 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 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 => 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 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
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()
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 process EAGAIN if pipe if writing process writing processes present,else return 0 present, else 0 Else Read maximum number of characters up to requested position.
Pipe write operation Blocking Non-blocking no reading Send SIGPIPE to writing process process and return EPIPE locked pipe atomic write block calling EAGAIN possible, but not process enough space in pipe buffer
Pipe/FIFO write op(cont.) Blocking Non-blocking Buffer space write requested number of bytes sufficient for to buffer atomic write continue blocking as for blocking Else until requested write. Write number of bytes maximum has been written. Possible number of bytes.
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 yet read to address arg. • pipe_lseek():invalid.