InterProcess Communication Shared Memory Message Passing Pipe Sockets

  • Slides: 33
Download presentation

进程间通信 • 进程合作要求提供进程间通信(Inter-Process Communication)机制 • 共享存储器(Shared Memory) • 消息传递(Message Passing) • 管道(Pipe) • 套接字(Sockets)

进程间通信 • 进程合作要求提供进程间通信(Inter-Process Communication)机制 • 共享存储器(Shared Memory) • 消息传递(Message Passing) • 管道(Pipe) • 套接字(Sockets) 2021/2/20 CH 04 Inter-Process Communication 4

通信方式 • 接收者与发送者之间的关系 2021/2/20 CH 04 Inter-Process Communication 13

通信方式 • 接收者与发送者之间的关系 2021/2/20 CH 04 Inter-Process Communication 13

消息缓冲机制 • 消息缓冲区结构 typedef struct message_buffer { int size; //消息长度 char *text; //消息正文 int

消息缓冲机制 • 消息缓冲区结构 typedef struct message_buffer { int size; //消息长度 char *text; //消息正文 int sendername; //发送者名字 ptr. Queue next; //消息队列指 针 } 2021/2/20 CH 04 Inter-Process Communication 22

消息缓冲机制 • 发送原语 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.

消息缓冲机制 • 发送原语 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 2021/2/20 Procedue send(receiver, a) begin getbuf(a. size, i); //申请缓冲区,i i. sender : = a. sender; // 将发送区中的信息 i. size : = a. size; // 复制到消息缓冲区i中 i. text : = a. text; i. next : = 0; getid(PCBSet, receiver, j); //获得接收进程的内部标识符 P(j. mutex); insert(j. Pm, i); //将消息插入到接收者的消息队列 V(j. mutex); V(j. Sm); End; CH 04 Inter-Process Communication 24

消息缓冲机制 • 接收原语 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.

消息缓冲机制 • 接收原语 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 2021/2/20 Procedure receive(b) Begin j : = internal name; // 为接收者进程的内部标识 P(j. Sm); P(j. mutex); remove(j. Pm, i); // 将消息队列中的第一个消息移出 V(j. mutex); b. sender : = i. sender; //将消息缓冲区 i 中的信息 b. size : = i. size; //复制到接收区b b. text : = i. text; End; CH 04 Inter-Process Communication 25