【文章內(nèi)容簡介】
on the size of the 沒有對緩沖區(qū)大小的限制 ? boundedbuffer assumes that there is a fixed buffer 緩沖 對緩沖區(qū)大小作了限定 2020年 9月 26日 12時(shí) 27分 Operating System Concepts BoundedBuffer – SharedMemory Solution ? The Buffer may either be provided by the operating system through the use of an interprocessmunication (IPC) facility (Sec ) , or by explicitly coded by the application programmer with the use of shared memory . ? SharedMemory Solution to the BoundedBuffer problem : Shared data define BUFFER_SIZE 10 Typedef struct { . . . } item。 item buffer[BUFFER_SIZE]。 int in = 0。 int out = 0。 2020年 9月 26日 12時(shí) 27分 Operating System Concepts BoundedBuffer – Producer Process Producer : item nextProduced。 while (1) { produce an item in nextProduced 。 while (((in + 1) % BUFFER_SIZE) == out) 。 /* do nothing */ buffer[in] = nextProduced。 in = (in + 1) % BUFFER_SIZE。 } Solution is correct, but can only use BUFFER_SIZE1 elements Buffer is full Why? How to improve? 2020年 9月 26日 12時(shí) 27分 Operating System Concepts BoundedBuffer – Consumer Process Consumer : item nextConsumed。 while (1) { while (in == out) 。 /* do nothing */ nextConsumed = buffer[out]。 out = (out + 1) % BUFFER_SIZE。 consume the item in nextConsumed 。 } ? In Chap 7 we discuss how synchronization among cooperating processes . Buffer is empty 2020年 9月 26日 12時(shí) 27分 Operating System Concepts Interprocess Communication (IPC) 進(jìn)程間通信 ? IPC provides a Mechanism for processes to municate and to synchronize their actions without sharing the same address space . IPC提供 無須共享相同地址空間可用于進(jìn)程通信的機(jī)制,同步其間的活動 ? IPC is best provided by a messagepassing system . ? signal( 信號機(jī)制) :給其他進(jìn)程發(fā)送異步事件信號。如: kill –9 pid :向 pid 進(jìn)程發(fā)送 9號信號(無條件終止) kill –l : 顯示系統(tǒng)中所有的信號 ls –l | wc –l :求出當(dāng)前目錄下的文件數(shù) ? pipe( 管道技術(shù)) :一個(gè)進(jìn)程的輸出作為另外一個(gè)進(jìn)程的輸入,實(shí)現(xiàn)相關(guān)進(jìn)程(如父子進(jìn)程)通信,可看作一個(gè)臨時(shí)文件。如: ? 無名管道( pipe): ls –l | grep ?^d‘, 實(shí)現(xiàn)相同父進(jìn)程的子進(jìn)程間通信。 ? 命名管道 (named pipe, FIFO): 是有名字的管道,在 OS中作為一個(gè)對象(文件,即FIFO文件)存在,實(shí)現(xiàn)任何進(jìn)程間通信 ? mkfifo pipename ? ls –l pipename amp。 wc –l pipename 2020年 9月 26日 12時(shí) 27分 Operating System Concepts MessagePassing System消息傳遞系統(tǒng) ? Message system – processes municate with each other without resorting to shared variables. 消息系統(tǒng) 進(jìn)程間通信無須對共享變量進(jìn)行再分類 ? IPC facility provides two operations:IPC提供兩個(gè)操作 : ?send(message) – message size fixed or variable 發(fā)送 固定或可變大小消息 ?receive(message) 接受 2020年 9月 26日 12時(shí) 27分 Operating System Concepts MessagePassing System (Cont.) ? If P and Q wish to municate, they need to: 若 P與 Q要通信,需要 : ?establish a munication link between them 建立通信連接 ?exchange messages via send/receive 通過 send/receive交換消息 ? Implementation of munication link通信連接的實(shí)現(xiàn) ?physical (., shared memory, hardware bus) 物理的(如,共享存儲,硬件總線) ? logical (., logical properties) 邏輯的(如,邏輯特性) 2020年 9月 26日 12時(shí) 27分 Operating System Concepts MessagePassing System (Cont.) ? several method for implementing a link and the send / receive operation : 實(shí)現(xiàn)鏈接的幾種方法和發(fā)送 /接收操作 : ?Direct or indirect munication 直接或間接的通信 ?Symmetric or asymmetric munication 同步或異步通信 ?Automatic or explicit buffering 自動或顯式的緩沖 ?Send by copy or send by reference 通過拷貝或通過引用發(fā)送 ?Fixedsized or variablesized message 固定大小或可變大小的消息 2020年 9月 26日 12時(shí) 27分 Operating System Concepts Implementation Questions實(shí)現(xiàn)中的問題 ? How are links established?連接如何建立? ? Can a link be associated with more than two processes?連接可同多于兩個(gè)的進(jìn)程相關(guān)嗎? ? How many links can there be between every pair of municating processes? 每對在通信進(jìn)程有多少連接? ? What is the capacity of a link?一個(gè)連接的容量是多少? ? Is the size of a message that the link can acmodate fixed or variable? 連接可使用的固定或可變消息的大小? ? Is a link unidirectional or bidirectional? 連接是無向的還是雙向的? 2020年 9月 26日 12時(shí) 27分 Operating System Concepts Naming命名 Direct Communication直接通信 ? Processes must name each other explicitly: 進(jìn)程必須互相顯式的命名 ?send (P, message) – send a message to process P 向進(jìn)程 P發(fā)消息 ?receive(Q, message) – receive a message from process Q 從進(jìn)程 Q收消息 2020年 9月 26日 12時(shí) 27分 Operating System Concepts Direct Communication直接通信 ? Properties of munication link通信連接的特性 ?Links are established ?A link is associated with exactly one pair of municating processes. 連接精確的與一對在通信的進(jìn)程相關(guān) ?Between each pair there exists exactly one link. 在每一對之間就存在一個(gè)連接 ?The link may be unidirectional, but is usually bidirectional. 連接可以單向的,但通常是雙向的 2020年 9月 26日 12時(shí) 27分 Operating System Concepts Indirect Communication 間接通信 ? Messages are directed and received from mailboxes (also referred to as ports). 消息導(dǎo)向至信箱并從信箱接收(被視作端口) ?Each mailbox has a unique id. 每一個(gè)信箱有一個(gè)唯一的 id ?Processes can mun