淡江大學 考試科目: 作業系統應用 97 學年度第 2 學期 考試命題紙 開課班別: 資管 系 3 年 B 班 命題教授:周清江 (B5 白紙)或答案紙請在試題內封袋備註。 考試日期: 4 月 24 日(星期 五 )第 1 節 ※ 請務必註記,准帶項目打「V」,否則打「X」。1.需加發計算紙 2.本命題紙為A4 大小,印刷格式統一由闈場判斷是否放大 典 或合併印刷,如有特殊需求,請註記: 本試題共 4 頁,附件共 0 頁,印刷份數: 60 份 計算機 課本 筆記 字 電子辭典 其他 備註: x x x x x 一、選擇題 (30 分,每題 2 分) 1. Which of the following description about race condition is true? (A) A race condition results when several threads try to access the same data concurrently. (B) A race condition results when several threads try to access and modify the same data concurrently. (C) A race condition will result only if the outcome of execution does not depend on the order in which instructions are executed. 2. Which of the following is not included in the requirement of a solution to the critical section? (A) Mutual exclusion. (B) Progress (C) Bounded waiting (D) Non-preemptive. 3. An instruction that executes atomically _______. (A) must consist of only one machine instruction (B) cannot be used to solve the critical section problem (C) executes as a single, uninterruptible unit. 4. A spinlock ____. (A) is never advantageous (B) will ultimately result in a context switch when a process must wait on a lock (C) does not require a context switch when a process must wait on a lock (D) is useful when locks are expected to be held for long amounts of time. 5. In Windows XP Synchronization, which of the following is false? (A) Uses interrupt masks to protect access to global resources on uni-processor systems (B) Uses spinlocks on multiprocessor systems (C) provides dispatcher objects which may act as either mutexes and semaphores (D) Dispatcher objects may provide events, so it does not provide timers. 6. Which of the following is not a necessary condition of deadlock? (A) Mutual exclusion (B) Hold and wait (C) Preemption (D) Circular wait 7. The witness software product is a(n) ____. (A) lock-order verifier that uses mutual-exclusion locks to protect critical sections (B) modeler to develop resource allocation graphs (C) driver that can be used to prevent mutual exclusion for non-sharable resources (D) implementation of the banker's algorithm available for most operating systems. 8. A cycle in a resource-allocation graph is ____. (A) a necessary and sufficient condition for deadlock in the case that each resource has more than one instance (B) a necessary and sufficient condition for a deadlock in the case that each resource has exactly one instance (C) a sufficient condition for a deadlock in the case that each resource has more than one instance (D) is neither necessary nor sufficient for indicating deadlock in the case that each resource has exactly one instance. 9. Which of the following is most often used by operating systems to handle deadlocks? (A) Pretend that deadlocks never occur (B) Use protocols to prevent or avoid deadlocks (C) Detect and recover from deadlocks 10. Which of the following statements is true? (A) A safe state is a deadlocked state. (B) A safe state may lead to a deadlocked state. (C) An unsafe state is necessarily, and by definition, always a deadlocked state. (D) An unsafe state may lead to a deadlocked state. 11. Suppose that the operating system uses two internal tables to keep track of open files. Process one has two files open an.d process two has three files open. Two files are shared between the two processes. How many entries are in the per-process table of process one, the per-process table of process two, and the system-wide tables respectively? (A) 5, 5, 5 (B) 2, 3, 3 (C) 2, 3, 5 (D) 2, 3, 1 第1頁 注意:1、考試求公平及公正,請同學務必自律,維護學校與學生之榮譽。 2、考試時不得有交談、攜卷出場、窺視、傳遞、代考、夾帶等違規行為,違者將受嚴重議處。 淡江大學 考試科目: 作業系統應用 97 學年度第 2 學期 考試命題紙 開課班別: 資管 系 3 年 B 班 命題教授:周清江 (B5 白紙)或答案紙請在試題內封袋備註。 考試日期: 4 月 24 日(星期 五 )第 1 節 ※ 請務必註記,准帶項目打「V」,否則打「X」。1.需加發計算紙 2.本命題紙為A4 大小,印刷格式統一由闈場判斷是否放大 典 或合併印刷,如有特殊需求,請註記: 本試題共 4 頁,附件共 0 頁,印刷份數: 60 份 計算機 課本 筆記 字 電子辭典 其他 備註: x x x x x 12. The simplest file access method is ____. (A) sequential access (B) logical access (C) relative access (D) direct access. 13. Which of the following is true of the direct access method? (A) It is the most common mode of access. (B) It allows programs to read and write records in no particular order. (C) Files are made up of variable-length records. (D) It is not a good method for accessing large amounts of data quickly. 14. Which of the following is true of the tree directory structure? (A) Users cannot create their own subdirectories. (B) Users cannot acquire permission to access the files of other users. (C) Directories can share subdirectories and files. (D) It is the most common directory structure. 15. An acyclic graph directory structure ____. (A) does not allow the sharing of files. (B) is less complicated than a simple tree directory structure. (C) allows the sharing of subdirectories and files. (D) is less flexible than a simple tree directory structure. 二、解釋名詞 (15 分,每題 3 分) 1. starvation: a situation in which processes wait indefinitely. 2. busy waiting: while a process is in its critical section, any other process that tries to enter its critical section must loop continuously in the entry code. 3. circular wait (a necessary condition of deadlock): there exists a set {P0, P1, …, Pn} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and Pn is waiting for a resource that is held by P0. 4. link (as a directory entry): A pointer to another file or subdirectory. 5. mandatory file locking: file locking is mandatory imposed on all file access operations by the operating system. 三、問答題 (65 分) 1. In the following bounded-waiting mutual exclusion with TestAndSet(), while (true) { 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 } // i is the process identifier 第2頁 注意:1、考試求公平及公正,請同學務必自律,維護學校與學生之榮譽。 2、考試時不得有交談、攜卷出場、窺視、傳遞、代考、夾帶等違規行為,違者將受嚴重議處。 淡江大學 考試科目: 作業系統應用 97 學年度第 2 學期 考試命題紙 開課班別: 資管 系 3 年 B 班 命題教授:周清江 (B5 白紙)或答案紙請在試題內封袋備註。 考試日期: 4 月 24 日(星期 五 )第 1 節 ※ 請務必註記,准帶項目打「V」,否則打「X」。1.需加發計算紙 2.本命題紙為A4 大小,印刷格式統一由闈場判斷是否放大 典 或合併印刷,如有特殊需求,請註記: 本試題共 4 頁,附件共 0 頁,印刷份數: 60 份 計算機 課本 筆記 字 電子辭典 其他 備註: x x x x x (a) what are the shared data structures? (4 分) lock and the waiting[ ] array (b) Explain the idea of this solution. (5 分) (1) a process exiting the critical section either sets lock to false or sets waiting[j] to false. Both allow a process that is waiting to enter its critical section to proceed. (could be skipped) (2) When process i leaves its critical section, it scans the array waiting in the cyclic ordering (i+1, i+2, …, n-1, 0, …, i-1). It designates the first process in this ordering that i sin the entry section (waiting[j] == true) as the next one to enter the critical section. Any process waiting to enter its critical section will thus do so within n-1 turns. 2. (a) What are the instructions for the wait( ) and signal( ) operations on a global semaphore variable S. (4 分) wait (S) { while S <= 0 ; S--; } signal(S) { S++; } (b) Servers can be designed to limit the number of open connections. For example, a server may wish to have only N socket connections at any point in time. As soon as N connections are made, the server will not accept another incoming connection until an existing connection is released. Explain how semaphores can be used by a server to limit the number of concurrent connections. (6 分) A semaphore is initialized to N, the number of allowable open socket connections. When a connection is accepted, the wait() method is called, when a connection is released, the signal() method is called. If the system reaches the number of allowable socket connections, subsequent calls to wait() will block until an existing connection is terminated and the release method is invoked. 3. The following are the solutions for the classic readers-writers problem. (a) what are the initial values of the semaphores mutex and wrt? (4 分) 1, 1 (b) Explain why this solution satisfies the requirement “No reader should be kept waiting unless a writer has obtained permission to use the shared object”. (5 分) The readcount variable keeps track of how many processes are currently reading the object. The semaphore wrt is used by the first or last reader that enters or exits the critical section. It is not used by readers who enter or exit while other readers are in their critical section. 第3頁 注意:1、考試求公平及公正,請同學務必自律,維護學校與學生之榮譽。 2、考試時不得有交談、攜卷出場、窺視、傳遞、代考、夾帶等違規行為,違者將受嚴重議處。 淡江大學 考試科目: 作業系統應用 97 學年度第 2 學期 考試命題紙 開課班別: 資管 系 3 年 B 班 命題教授:周清江 (B5 白紙)或答案紙請在試題內封袋備註。 考試日期: 4 月 24 日(星期 五 )第 1 節 ※ 請務必註記,准帶項目打「V」,否則打「X」。1.需加發計算紙 2.本命題紙為A4 大小,印刷格式統一由闈場判斷是否放大 典 或合併印刷,如有特殊需求,請註記: 本試題共 4 頁,附件共 0 頁,印刷份數: 60 份 計算機 課本 筆記 字 電子辭典 其他 備註: x x x x x // The structure of a writer process while (true) { // The structure of a reader process while (true) { wait (mutex) ; readcount ++ ; if (readercount == 1) wait (wrt) ; signal (mutex); // reading is performed wait (mutex); readcount - - ; if (redacount == 0) signal (wrt) ; signal (mutex) ; wait (wrt) ; // writing is performed signal (wrt) ; } 4. } A system cannot detect that some of its processes are starving. The system could use an extremely large time period T to detect pseudo-starving so that if a process have been waiting longer than T, then it is considered as starving. In this case, describe one strategy the system could use to prevent starvation. (4 分) One strategy for dealing with starvation would be to adopt a policy where resources are assigned only to the process that has been waiting the longest. For example, if process Pa has been waiting longer for resource X than process Pb , the request from process Pb would be deferred until process Pa ’s request has been satisfied. OR Another strategy would be less strict than what was just mentioned. In this scenario, a resource might be granted to a process that has waited less than another process, providing that the other process is not starving. However, if another process is considered to be starving, its request would be satisfied first. 5. Suppose all the resource types have only one instance. Please identify the processes involved in the two deadlocks in the following diagram. (6 分) 第4頁 注意:1、考試求公平及公正,請同學務必自律,維護學校與學生之榮譽。 2、考試時不得有交談、攜卷出場、窺視、傳遞、代考、夾帶等違規行為,違者將受嚴重議處。 淡江大學 考試科目: 作業系統應用 97 學年度第 2 學期 考試命題紙 開課班別: 資管 系 3 年 B 班 命題教授:周清江 (B5 白紙)或答案紙請在試題內封袋備註。 考試日期: 4 月 24 日(星期 五 )第 1 節 ※ 請務必註記,准帶項目打「V」,否則打「X」。1.需加發計算紙 2.本命題紙為A4 大小,印刷格式統一由闈場判斷是否放大 典 或合併印刷,如有特殊需求,請註記: 本試題共 4 頁,附件共 0 頁,印刷份數: 60 份 計算機 課本 筆記 字 電子辭典 其他 備註: x x x x x P1, P2, P4 6. and P1, P2, P3, P4 Consider the following snapshot of a system. Using the banker’s algorithm to perform deadlock avoidance. Please answer the following questions: (a) How many instances for each resource type are there in the system? (3 分) (6, 2, 7) (b) What is the content of the matrix Need? (3 分) see below (c) Use the system snapshots to show why or why not the request (0, 0, 1) by P1 be granted immediately. (3 分) (d) Use the system snapshots to show why or why not the request for (1, 0, 0) by P2 be granted immediately. (3 分) P0 P1 P2 P3 Allocation A B C 1 0 0 2 1 2 2 1 1 0 0 2 Max Request A B C 3 2 2 3 1 3 3 1 4 4 2 2 Available A B C 1 0 2 Need A B C 2 2 2 1 0 1 1 0 3 4 2 0 (c) If the request (0, 0, 1) by P1 is granted, then the system snap shot is: P0 P1 P2 P3 Allocation A B C 1 0 0 2 1 3 2 1 1 0 0 2 Max Request A B C 3 2 2 3 1 3 3 1 4 4 2 2 Available A B C 1 0 1 Need A B C 2 2 2 1 0 0 1 0 3 4 2 0 The sequence <P1, P2, P0, P3> (or <P1, P2, P3, P0> ) shows that resulting system is safe. So it can be granted immediately. (d) If the request (1, 0, 0) by P2 is granted, then the system snap shot is: P0 P1 P2 P3 Allocation A B C 1 0 0 2 1 2 3 1 1 0 0 2 Max Request A B C 3 2 2 3 1 3 3 1 4 4 2 2 Available A B C 0 0 2 Need A B C 2 2 2 1 0 1 0 0 3 4 2 0 We could not a sequence to show that resulting system is safe. So it cannot be granted immediately. 7. In case a deadlock is detected, what are the two ways the system could recover from the deadlock? (4 第5頁 注意:1、考試求公平及公正,請同學務必自律,維護學校與學生之榮譽。 2、考試時不得有交談、攜卷出場、窺視、傳遞、代考、夾帶等違規行為,違者將受嚴重議處。 淡江大學 考試科目: 作業系統應用 97 學年度第 2 學期 考試命題紙 開課班別: 資管 系 3 年 B 班 命題教授:周清江 (B5 白紙)或答案紙請在試題內封袋備註。 考試日期: 4 月 24 日(星期 五 )第 1 節 ※ 請務必註記,准帶項目打「V」,否則打「X」。1.需加發計算紙 2.本命題紙為A4 大小,印刷格式統一由闈場判斷是否放大 典 或合併印刷,如有特殊需求,請註記: 本試題共 4 頁,附件共 0 頁,印刷份數: 60 份 計算機 課本 筆記 字 電子辭典 其他 備註: x x x x x 分) (1) Abort one or more processes to break the circular wait (2) Preempt some resources from one or more of the deadlocked processes 8. List three operations that could be performed on a directory. (3 分) Search for a file, Create a file, Delete a file, List a directory, Rename a file, Traverse the file system 9. Please draw pictures for the four common directory structures described in Chapter 10. ( 8 分) single-level two-level acyclic-graph tree 第6頁 注意:1、考試求公平及公正,請同學務必自律,維護學校與學生之榮譽。 2、考試時不得有交談、攜卷出場、窺視、傳遞、代考、夾帶等違規行為,違者將受嚴重議處。