资源预览内容
第1页 / 共93页
第2页 / 共93页
第3页 / 共93页
第4页 / 共93页
第5页 / 共93页
第6页 / 共93页
第7页 / 共93页
第8页 / 共93页
第9页 / 共93页
第10页 / 共93页
亲,该文档总共93页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
Operating Systems,Department of Computer Science & Technology Tsinghua University,Lecture 15 Inter-Process Communication and Deadlock,Outline,IPC Overview Communications Models Direct&Indirect Communication Blocking and Non-blocking Buffer of Communication Link Signal Pipe Message Queue Shared Memory,Deadlocks Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock,IPC Overview,Mechanism for processes to communicate and to synchronize their actions Processes communicate with each other without resorting to shared variables IPC facility provides two operations: send(message) message size fixed or variable receive(message) If P and Q wish to communicate, they need to: establish a communication link between them exchange messages via send/receive Implementation of communication link physical (e.g., shared memory, hardware bus) logical (e.g., logical properties),Communications Models,Implementation Questions,How are links established? Can a link be associated with more than two processes? How many links can there be between every pair of communicating processes? What is the capacity of a link? Is the size of a message that the link can accommodate fixed or variable? Is a link unidirectional or bi-directional?,Direct Communication,Processes must name each other explicitly: send (P, message) send a message to process P receive(Q, message) receive a message from process Q Properties of communication link Links are established automatically A link is associated with exactly one pair of communicating processes Between each pair there exists exactly one link The link may be unidirectional, but is usually bi-directional,Indirect Communication,Messages are directed and received from message queues Each message queue has a unique id Processes can communicate only if they share a message queue Properties of communication link Link established only if processes share a common message queue A link may be associated with many processes Each pair of processes may share several communication links Link may be unidirectional or bi-directional,Indirect Communication,Operations create a new message queue send and receive messages through message queue destroy a message queue Primitives are defined as: send(A, message) send a message to Queue A receive(A, message) receive a message from Queue A,Indirect Communication,Message queue sharing P1, P2, and P3 share message queue A P1, sends; P2 and P3 receive Who gets the message? Solutions Allow a link to be associated with at most two processes Allow only one process at a time to execute a receive operation Allow the system to select arbitrarily the receiver. Sender is notified who the receiver was.,Blocking and Non-blocking,Message passing may be either blocking or non-blocking Blocking is considered synchronous Blocking send has the sender block until the message is received Blocking receive has the receiver block until a message is available Non-blocking is considered asynchronous Non-blocking send has the sender send the message and continue Non-blocking receive has the receiver receive a valid message or null,Buffering,Queue of messages attached to the link; implemented in one of three ways 1. Zero capacity 0 messages Sender must wait for receiver (rendezvous) 2. Bounded capacity finite length of n messages Sender must wait if link full 3. Unbounded capacity infinite length Sender never waits,Outline,IPC Overview Signal Signal Generation Delivery Signal API Signal Example Pipe Message Queue Shared Memory Solaris Doors (opt),Deadlocks Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock,Signals,Signal Software interrupt that notifies a process of an event Examples: SIGFPE, SIGKILL, SIGUSR1, SIGSTOP, SIGCONT What happens when a signal is received? Catch: Specify signal handler to be called Ignore: Rely on OS default action Example: Abort, memory dump, suspend or resume process Mask: Block signal so it is not delivered May be temporary (while handling signal of same type) Disadvantage Does not specify any data to be exchanged,Signals,Divided into asynchronous (CTL-C) and synchronous (illegal address) Three phases to processing signals: generation: event occurs requiring process notification delivery: process recognizes and takes appropriate action pending: between generation and delivery,Signals,Asynchronous signal: ctrl-C child process completes alarm scheduled by the process expires Unix: SIGALRM from alarm() or setitimer() resource limit exceeded (disk quota, CPU time.) Synchronous signal: programming errors, such as invalid data, divide by zero SIGTRAP: a condition arises that a debugger has requested to be informed of. SIGBUS: a bus error SIGSEGV: an invalid memory reference, or segmentation fault. SIGFPE: an erroneous arithmetic operatio
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号