11CSE 380Computer Operating SystemsInstructor: Insup LeeUniversity of PennsylvaniaFall 2003Lecture Note 2.6: Message-Based Communication2Interprocess communicationq Shared Memoryq Message Passingß Signals23Shard MemoryProcess 1 Process 2 Process 3Shared memory4Shared Memory in Solarisq Processes can share the same segment of memory directlywhen it is mapped into the address space of each sharingprocessq Faster communicationq System calls:ßint shmget(key_t key, size_t size, int shmflg) :creates a new region of shared memory or returns anexisting oneßvoid *shmat(int shmid, const void *shmaddr, intshmflg) : attaches a shared memory region to thevirtual address space of the processßint shmdt(char *shmaddr):detaches a shared regionq Mutual exclusion must be provided by processes using theshared memory35Message Passingmessage6Design Attributesq Namingß Process id, mailboxq Bufferingß Size: zero, bounded, unboundedß Place: kernel space, user spaceq Send operationß Synchronous vs. asynchronousq Receive operationß Blocking vs. non-blocking47Interprocess CommunicationMessage PassingMany possible naming schemes. One is direct naming: send(process_id, message)receive(process_id, buffer)Exampleprocess P1: process P2: declare x integer declare y integer . . send(P2, x) receive(P1, y) . .end process end processEffect of this communication is y := x | \ local var local var of P2 of P18Buffering• A buffer, with bounded-buffer synchronization, can beassociated with each pair of communicating processes.• A “zero-capacity” buffer means processes must “handshake” inorder to communicate.q A buffer can reside in memory of receiving process or in OSaddres space.Examples:q no buffer needed P1: send(P2, x) P2: receive(P1, x) receive(P2, y) send(P1, y)q buffer needed P1: send(P2, x) P2: send(P1, x) receive(P2, y) receive(P1, y)59Mailboxesq Also known as message queues, portsq The explicit and symmetric naming of processes in directnamingq fi Limited modularity since changing the name of a processrequires changes elsewhere, i.e., in definitions of otherprocessesmboxPRP or Q callsend(mbox-id, message)R callsreceive(mbox-id, message)Q10Mailbox Issues• communication is no longer “point-to-point”; e.g., amessage received by R may be from P or Q• “fair merge” property --- do not starve Q from queuingmessages by allowing continual queuing of messagesonly from P• natural extension to multiple receivers. Possiblesemantics:• Multicast to all in the group gets the same message• The first receiver removes it• Bulletin board: each receiver
View Full Document