OS作业系统报告(第二部分).pptVIP

  • 3
  • 0
  • 约2.53千字
  • 约 10页
  • 2018-03-03 发布于河南
  • 举报
OS作业系统报告(第二部分)

OS作業系統報告(第二部分) Outline: Semaphore(信號) a. What’s Semaphore b. System call about Semaphore Shared memory (共享記憶體) a. What’s Shared memory b. System call about Shared memory Semaphore(信號)- a. What’s emaphore Introduction: “a data structure that is shared by several processes “ Why use that: 1. avoid starvation: indefinite blocking.產生一個行程一直被拒絕存取所需要的資源時發生的問題. 2. avoid deadlock: 在兩個或是多個行程中,每一個都含有對方需要的資源,同時又等待著其他行程釋出資源時發生的問題. Two method : binary counting Binary semaphore: 0?資源正在使用中, 1?資源可使用. Counting semaphore:數值不受限制, 正數,非零的數值?資源可使用的. 0?資源無法使用. struct sem { int semval; /* 目前的數值 */ int sempid; /* 信號上操作的最後一個行程的ID */ }; 當目前信號值為0的時候, 表示資源無法使用,所要求的process必須等待, 當 信號值增加(有資源返回)時, 系統會通知正在等待資源的process. Semaphore(信號)- b. System call semget, semctl, semop System call semget: 建立semaphore, or 存取一個存在的semaphore. int semget (key_t key, int nsems, int semflg); semctl: 讓使用者在信號上執行各種一般性的控制作業 int semctl (int semid, int semnum, int cmd, union semun arg); 允許使用者設定起始信號數值,取得目前數值並移除信號… semop: 在個別semaphore上的其他作業. int semop( int semid, struct sembuf *sops, unsigned nsops); Semaphore是一種structure. Process使用semaphore來判斷某一特定的資源是否能夠使用. 如果不能使用,系統會將要求的process放在一個相關的佇列中. 可以使用時,會通知等候的process. Semaphore可以分為兩種形式,binary and couning binary可用來同步對於非共享資源的單一實例存取. counting可用於非共享資源的多個實例存取. Shared memory (共享記憶體) a. What’s Shared memory 共享記憶體可讓多個行程共享虛擬的記憶體空間. 流程簡述: 1. process 會先建立或配置共享記憶體區段. 2. process連接共享區段. 使對應到process目前的資料空間. 每一process都會存取與其連接位址相關的共享記憶體. 當process完成 “此共享的記憶體區段”之後, process變可中斷與他的連接. b.System call about Shared memory shmget, shmctl, shmatshmdt shmget: 用來建立共享記憶體區段,並產生相關的系統資料結構.或存取現有的區段. int shmget( key_t key, int size, int shmflg); shmctl: 允許使用者在現有的共享記憶體區段及系統共享記憶體資料結構上執行一些一般性的控制作業. int shmctl( int shmid, int cmd, struct shmid_ds *buf); shmop: 1. shmat : 將

文档评论(0)

1亿VIP精品文档

相关文档