[理工] 一些OS題目

看板Grad-ProbAsk作者 (choco)時間12年前 (2013/11/11 22:43), 編輯推噓2(2015)
留言17則, 2人參與, 最新討論串1/1
一些題目不會寫也不知從何找解答 只好來請教大家 1. List four situations in which CPU scheduling decisions may take place. 2. What is the reason, from the perspective of system security that OS should not allow a process to simply disable/enable interrupt to achieve the mutual exclusion of the critical section problem? 3. 3.1 Why a non-preemptive OS cannot assign the CPU occupied by a busy-waiting process to another process? 3.2 Please use atomic operation Swap() to implement binary semaphore’s two operations (Busy-waiting is fine). 3.3 Please use block() and wakeup() to implement semaphore’s two operations with no busy waiting. 4. Use multilevel queue to design a scheduler which can distinguish I/O-bound programs from CPU-bound program. Please explain how it can achieve the goal. 5. The following code guarantees bounded-waiting mutual exclusion which is done by adding the highlighted code. Please explain how these highlighted codes may achieve bounded-waiting mutual exclusion. do{ waiting[i] = TRUE; key=TRUE; while( waiting[i] && key ) key = TestAndSet( &lock ); waiting[i] = FALSE; // critical section j = ( i+1 ) % n; While( ( j!=i ) && !waiting[j] ) j = ( j+1 ) % n; if( j == i ) lock = FALSE; else waiting[j] = FALSE; // remainder section } while( TRUE ); 6. Illustrate the priority inversion problem and its solution. 7. Write down a code in which a parent process (P0) will create two child process ( P1 and P2 ) such that P0 can send data to P1 via a pipe, P1 can send data to P2 via a pipe, P2 can send data to P0 via a pipe. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.161.96.202

11/11 23:10, , 1F
1. RUN > READY, RUN > WAIT, NEW > READY, RUN > EXIT
11/11 23:10, 1F

11/11 23:15, , 2F
2. 這樣i/o無法即時得到服務,可能miss掉一些東西,比方
11/11 23:15, 2F

11/11 23:16, , 3F
收到網路封包,如果disable,os無法即時處理,會先把封包
11/11 23:16, 3F

11/11 23:16, , 4F
丟到queue中,如果滿了,前面的就miss掉了。
11/11 23:16, 4F

11/11 23:19, , 5F
3.1 根據定義,除非自願,不然process不會放出cpu
11/11 23:19, 5F

11/11 23:20, , 6F
而在busy-waiting,顯然無法自願放出。
11/11 23:20, 6F

11/11 23:21, , 7F
3.2 在semaphore兩個運算的前面各用swap換一個lock,
11/11 23:21, 7F

11/11 23:21, , 8F
後面在用一個 lock = false;
11/11 23:21, 8F

11/11 23:23, , 9F
3.3 一樣,不過while裡面改用block,後面用wake up。
11/11 23:23, 9F

11/11 23:25, , 10F
高level的讓他的quantum小,低的大,這樣cpu bound的
11/11 23:25, 10F

11/11 23:25, , 11F
一下就被改下去,讓IO bound比較快。
11/11 23:25, 11F

11/11 23:28, , 12F
6. 高優先的process需要的資源,掌握在低優先權的手上
11/11 23:28, 12F

11/11 23:29, , 13F
解法是,讓低優先的在執行中有等待中高優先的權限,
11/11 23:29, 13F

11/11 23:29, , 14F
讓他快速完成,以釋放資源。
11/11 23:29, 14F

11/12 00:44, , 15F
蠻好奇題目從哪來的 補充第6題 有印象 後來翻恐龍發現
11/12 00:44, 15F

11/12 00:45, , 16F
有講完全一模一樣code p233去查 有講運作
11/12 00:45, 16F

11/12 00:48, , 17F
是第5題才對==
11/12 00:48, 17F
文章代碼(AID): #1IWEqhdt (Grad-ProbAsk)