OPERATING SYSTEM_process2_Interprocess Communication

OPERATING SYSTEM

process2

interprocess communication进程间通信

0.概述一下

0.1
Processes within a system may be independent or cooperating操作系统内并发执行的进程可以是独立进程或协作进程。Cooperating process can affect or be affected by other processes, including sharing data与其他进程共享数据的进程是协作进程

说白了,进程间通信就是进程之间的信息交换

0.2 Reasons for cooperating processes四个理由

  • Information sharing信息共享(允许对共享信息进行并发访问)
  • Computation speedup 提高运算速度(把任务分成子任务并行执行)
  • Modularity模块化(可将系统功能分成独立进程或线程)
  • Convenience方便(单个用户也能同时执行许多任务)

0.3IPC基本模式
(1)shared memory共享内存
(2)message passing消息传递

共享内存比消息传递快

1.Shared Memory共享内存

1.1 Producer-Consumer Problem
生产者进程产生信息以供消费者进程消费,共享内存可以解决这个问题,它允许生产者进程和消费者进程能并发执行。

  • unbounded-buffer无限缓冲:缓冲区无限制
  • bounded-buffer有限缓冲:缓冲区有限,空:消费者等待;满:生产者等待
    在这里插入图片描述
    最多允许缓冲的最大项数为buffer_size-1
    1.2 特点
    1.The communication is under the control of the users processes not the operating system.机制由用户控制(消息传递是操作系统提供)
    2.设置了一个共享的地址空间

2.Message Passing消息传递

2.1 特点
1.是操作系统提供的机制
2.Message system – processes communicate with each other without resorting to shared variables消息系统–进程之间相互通信,而无需求助于共享变量
3.IPC facility provides two operations:
send(message)
receive(message)
IPC设施提供两种操作: send receive
3.The message size is either fixed or variable消息大小是固定的或可变的
4.If processes P and Q wish to communicate, they need to:
Establish a communication link between them在它们之间建立通信链接
Exchange messages via send/receive 通过send/receive交换消息
5.通讯连接的实现(logic)
Direct or indirect直接或间接
Synchronous or asynchronous同步或异步
Automatic or explicit buffering自动或显式缓冲

2.2 Direct Communication直接通信
1.进程必须彼此命名
在这里插入图片描述
2.

  • 自动建立线路
  • 一个线路只于两个进程相关
  • 每对进程之间只有一个线路
    在这里插入图片描述
    2.3 Indirect Communication间接通信
    1.消息通过邮箱📮中转
    在这里插入图片描述
    在这里插入图片描述
    2.运作方式Operations
    create a new mailbox (port)
    send and receive messages through mailbox
    destroy a mailbox破坏邮箱!!!

2.4 同步
在这里插入图片描述
2.5 缓冲
不管通信是直接的还是间接的,通信进程所交换的消息都驻留在queue–临时队列
implemented in one of three ways

  1. Zero capacity零容量 – no messages are queued on a link.Sender must wait for receiver (rendezvous) 线路中不能有任何消息排队,发送者必须等待
  2. Bounded capacity有限容量– finite length of n messagesSender must wait if link full 如果满了,发送者需要等待
  3. Unbounded capacity无限容量 – infinite length Sender never waits 发送者从不等待

3. Communications in Client-Server Systems客户机-服务器系统通信

3.1 sockets套接字

  1. A socket is defined as an endpoint for communication 套接字被定义为通信的端点
  2. Concatenation of IP address and port 由IP地址与一个端口号连接组成
    eg:The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8
    在这里插入图片描述
  3. 当客户机进程发出连接请求时,他被主机赋予一个端口,该端口是大于1024的一个任意数。
  4. JAVA提供Three types of sockets
    Connection-oriented (TCP)面向连接套接字
    Connectionless (UDP)无连接套接字
    MulticastSocket class– data can be sent to multiple recipients多点传送套接字

3.2 Remote Procedure calls (PRC)远程过程调用
用于通过网络连接系统
Stub存根: 是一小段代码,位于服务器的端口,并编组marshal参数。可以寻址、定位到你所请求的服务器,是一个代理。
存在的问题:客户机和服务器对于数字的编码形式不一致
解决:External Data Representation XDR–外部数据表示

4. pipes管道通信

4.1 ordinary pipes 特点
1.Ordinary Pipes allow communication in standard producer-consumer style普通管道允许以标准的生产者-消费者风格进行通信
2.Producer writes to one end (the write-end of the pipe)生产者写到一端(管道的写端)
3.Consumer reads from the other end (the read-end of the pipe)使用者从另一端读取(管道的读取端)
4.Ordinary pipes are therefore unidirectional普通管道是单向
4.Require parent-child relationship between communicating processes要求进程之间存在父子关系
在这里插入图片描述
4.2 named pipes 特点
1.Communication is bidirectional 双向
2.No parent-child relationship is necessary between the communicating processes无父子关系
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值