# Interprocess Communication 讓行程之間交換資料的方法 --- ## Independent process vs. Cooperating process - Independent process:不能(被)影響的行程 - Cooperating process:能被影響且影響其他行程,且能與其他行程共用資料 --- ## Communication Methods ### Shared memory - 需要仔細注意使用者的==同步化== - 用memory的實作,memory addr. access data,速度快 - 其中一個process,開自己的unshared memory成shared - ==Consumer & Producer Problem== Sol.:允許至多B-1個資料在array,否則無法決定buffer是空或是滿的 ![](https://i.imgur.com/ZI6C70Z.png) ### Message passing - 不會有衝突,對於小資料有效率 - Use send/recv message - 用==system call==實作,速度較慢 - 需要建一個communication link,交換資料用send/recv ![](https://i.imgur.com/vcCIKfu.png) #### communication link的實作 - physical:shared memory, HW bus, or network - logical:Direct or indirect communication、Blocking or non-blocking --- #### Direct communication: 1. 明確講出對方名稱 2. Send (P, message)、Receive (Q, message) 3. Link會自動建立,且一對一 #### Indirect communication 1. 訊息的收送透過mailbox(port),每個mailbox有獨特的id 2. 行程若是共享mailbox即可溝通,EX:Send (A, message) 3. 當行程共享mailbox,link建立,可以多對多 4. 收送同步化問題解決方法 - link的連結至多兩個process - 一個時間內只允許一個process執行receive的動作 - 系統隨意選==單一個==receiver,sender被通知是誰拿到 --- #### Synchronization - blocking:會等到func全部執行完,才return - non-blocking:只會知道有做這件事,但不會等到他完成之後,才return - message passing 選擇兩者之一 blocking (synchronous) non-blocking (asynchronous) ![](https://i.imgur.com/nrxIqiM.png) #### Buffer - 零容量:blocking send/receive - 有邊界容量:滿的話,sender會被block住 - 無邊界容量:sender永不會被block住 ### Sockets - ip&port 對應到process - Exchange ==unstructured stream of bytes== - data的parsing是依據client/server apllication ![](https://i.imgur.com/al8WY5n.png) ### Remote Procedure Calls - 跨電腦rpc,call function - 允許client呼叫server的procedure - Stubs – client-side proxy for the actual procedure on the server ![](https://i.imgur.com/tHtdH02.png) ![](https://i.imgur.com/btCZOl7.png)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up