(20pt)
(1) In multithreaded programs, the kernel informs an application about certain events using a procedure known as a(n) ______. A) signal B) upcall C) event handler D) pool
(2) In Pthreads, a parent uses the pthread_join() function to wait for its child thread to complete. What is the equivalent function in Win32? A) win32_join() B) wait() C) WaitForSingleObject() D) join()
(3) A process that has terminated, but whose parent has not yet called wait(), is known as a ______ process. A) zombie B) orphan C) terminated D) init
(4) Which of the following is true of cooperative scheduling? A) It requires a timer. B) A process keeps the CPU until it releases the CPU either by terminating or by switching to the waiting state. C) It incurs a cost associated with access to shared data. D) A process switches from the running state to the ready state when an interrupt occurs.
(5) Which of the following scheduling algorithms must be non-preemptive? A) SJF B) RR C) FCFS D) priority algorithms
(6) A race condition ______. A) results when several threads try to access the same data concurrently B) results when several threads try to access and modify the same data concurrently C) will result only if the outcome of execution does not depend on the order in which instructions are executed D) None of the above
(7) Which of the following statements is true? A) A counting semaphore can never be used as a binary semaphore. B) A binary semaphore can never be used as a counting semaphore. C) Spinlocks can be used to prevent busy waiting in the implementation of semaphore. D) Counting semaphores can be used to control access to a resource with a finite number of instances.
(8) 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.
(9) In a dynamically linked library, ______. A) loading is postponed until execution time B) system language libraries are treated like any other object module C) more disk space is used than in a statically linked library D) a stub is included in the image for each library-routine reference
(10) Suppose we have the following page accesses: 1 2 3 4 2 3 4 1 2 1 1 3 1 4 and that there are three frames within our system. Using the LRU replacement algorithm, what is the number of page faults for the given reference string? A) 14 B) 13 C) 8 D) 10
(1) kernel 透過 upcall 通知 user-level thread library 事件(scheduler activation 的機制);signal 是 UNIX 通知 process 的方式 → B
(2) Win32 用 WaitForSingleObject() 等 thread handle 結束;wait() 是 UNIX 等 child process 的 system call → C
(3) 已結束但 parent 還沒 wait():PCB 與 exit status 還留著,叫 zombie;orphan 是 parent 先結束、自己還在跑的 process → A
(4) cooperative = nonpreemptive:拿到 CPU 後只有自己結束或進入 waiting 才交出;A、D 是 preemptive 才有的(timer、interrupt 搶走 CPU);C 的共享資料成本也是 preemption 造成的 → B
(5) FCFS 只能等目前的 process 做完或 block,沒有 preemptive 版本;SJF 有 SRTF,priority 也有 preemptive 版,RR 靠 time quantum 搶佔 → C
(6) 多個 thread 同時存取並修改同一份資料、結果取決於執行順序 → B(只讀不會出問題,C 說反了)
(7) counting semaphore 初值 1 就能當 binary semaphore;binary semaphore 加計數變數也能做 counting semaphore;spinlock 本身就是 busy waiting;counting semaphore 初值設成資源數,wait() 拿一個、signal() 還一個 → D
(8) safe state 保證有 safe sequence,不會 deadlock;unsafe 只是不保證能避開,不等於 deadlock,但有可能走向 deadlock → D
(9) dynamic linking 在執行檔裡對每個 library routine 放一個 stub,執行時 stub 檢查該 routine 是否已在記憶體、沒有就載入,並把自己換成它的位址;延到執行時的是 linking,「loading 延後」是 dynamic loading;system library 當一般 object module 併入是 static linking;dynamic linking 的 library 只存一份、各程式共用,反而省 disk → D
(10) 3 個 frame,frames 由最久沒用到→最近用到:
| ref | 1 | 2 | 3 | 4 | 2 | 3 | 4 | 1 | 2 | 1 | 1 | 3 | 1 | 4 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| fault | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||||||
| frames | 1 | 12 | 123 | 234 | 342 | 423 | 234 | 341 | 412 | 421 | 421 | 213 | 231 | 314 |
fault 共 8 次 → C
(1) B (2) C (3) A (4) B (5) C (6) B (7) D (8) D (9) D (10) C