明新科技大學 九十七學年度第一學期 班級: 1. 2. 3. 4. 5. 6. 7. 8. 姓名: 資工系四技四年級 期中考試題 學號: (a)What is the purpose of interrupts? (b)What are the differences between a trap and an interrupt? (c)Can traps be generated intentionally by a user program? If so, for what purpose? (6 points) Describe three general methods for passing parameters to operating system. (3 points) List five services provided by an operating system that are designed to make it more convenient for users to use the computer system. (5 points) Describe the differences among the (a)short-term, (b)medium-term, and (c)long-term schedulers. (6 points) Draw a figure to show all of the process’s states while executing. (6 points) Briefly explain the three types for multi-thread models. (6 points) Which of the following scheduling algorithms could result in starvation? (a)first come first served, (b)shortest job first, (c)round robin, and (d)priority. (4 points) The next CPU burst is predicted as an exponential average of the measured lengths of previous CPU bursts. Let tn be the length of the nth CPU burst time, and let τn + 1 be our predicted value for the next CPU burst time. Then for α , 0 ≤ α ≤ 1 , define τn + 1 = αtn + (1 − α )τn . Explain what are the representing meanings for when (a) α = 0 , (b) α = 1 , and (c) α = 1 / 2 . (6 points) 9. Five jobs are waiting to be run. Their expected run times are 9, 6, 3, 5, and X. In what order should they be run to minimize average response time? The answer should depend on X. (Note that a job can not run until the previous job finishes.) (5 points) 10. About Queueing Network Analysis, the equation, known as Little’s Formula, is useful because it is valid for any scheduling algorithm and arrival distribution. Briefly explain the meanings for the parameter (a) n , (b) λ , and (c) W for equation n = λ × W . (5 points) 11. (a) What is the advantage of spinlock? (b) Do you think the spinlock is appropriate for single-processor or multi-processor systems? Give your reason. (5 points) 12. The Finishing Deadline indicated the time by which execution of the process must complete in real time applications. The Earliest Deadline First (EDF) policy tries to eliminate (or at least minimize) the number of processes, which suffer deadline overruns. Perform the EDF policy for the processes in the following table: (a) What is the order these five processes being scheduled? (5 points) (b) Which of the processes miss their deadlines? (5 points) 13. Consider the following set of processes, with the length of the CPU-burst time given in milliseconds: Process Burst Time Priority P1 10 5 P2 29 1 P3 3 3 7 4 P4 P5 12 2 The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0. (a) Draw four Gantt charts illustrating the execution of these processes using FCFS, SJF, a non-preemptive priority (a smaller priority number implies a higher priority), and RR (quantum=10) scheduling. (8 points) (b) What is the turnaround time of each process for each of the scheduling algorithms in question (a)? (4 points) (c) What is the waiting time of each process for each of the scheduling algorithms in question (a)? (4 points) (d) Which of the scheduling in question (a) results in the minimal average waiting time (overall all processes)? (2 points) 14. Assume that the two processes, P0 and P1, share the following variables: The following program is for process Pi (i=0 or 1), with Pj (j=1 or 0) being the other process. (a) What are the three requirements that must be satisfied to solve the critical-section problem? (6 points) (b) Does the following algorithm satisfy all the requirements for the critical-section problem? Why? Please give your reasons. (9 points) 【參考解答】 1. (a) An interrupt is a hardware-generated change-of-flow within the system. (b) An interrupt handler is summoned to deal with the cause of the interrupt; control is then returned to the interrupted context and instruction. A trap is a software-generated interrupt. An interrupt can be used to signal the completion of an I/O to obviate the need for device polling. (c) A trap can be used to call operating system routines or to catch arithmetic errors. 2. (a) Pass parameters in registers. (b) Registers pass starting addresses of blocks of parameters. (c) Parameters can be placed, or pushed, onto the stack by the program, and popped off the stack by the operating system. 3. (a) Program execution. (b) I/O operations. (c) File-system manipulation. (d) Communications. (e) Error detection. 4. (a) Short-term (CPU scheduler)—selects from jobs in memory those jobs that are ready to execute and allocates the CPU to them. (b) Medium-term—used especially with time-sharing systems as an intermediate scheduling level. A swapping scheme is implemented to remove partially run programs from memory and reinstate them later to continue where they left off. (c) Long-term (job scheduler)—determines which jobs are brought into memory for processing. The primary difference is in the frequency of their execution. The short-term must select a new process quite often. Long-term is used much less often since it handles placing jobs in the system and may wait a while for a job to finish before it admits another one. 5. 6. (a) Many-to-One—many user-level threads mapped to single kernel thread. (b) One-to-One—each user-level thread maps to kernel thread. (c) Many-to-Many—Allows many user level threads to be mapped to many kernel threads. 7. (a) First Come First Served - N, (b) Shortest Job First - Y, (c) Round Robin - N, (d) Priority - Y. 8. (a) α = 0 : τn = τn + 1 - means recent history has no effect, (b) α = 1 : τn + 1 = tn - means only the most recent CPU burst matters, (c) α = 1 / 2 : means recent history and past history are equally weighted. 9. X value X<3 3<X<5 5<X<6 6<X<9 9<X Running Order X3569 3X569 35X69 356X9 3569X 10. (a) n : the average queue length, (b) λ : the average arrival rate for new processes in the queue, (c) W : during the time a process will wait. 11. (a) Spinlock has an advantage in that no context switch may take considerable time. (b) Spinlock is not appropriate for single-processor systems because the condition that would break a process out of the spinlock could be obtained only by executing a different process. If the process is not relinquishing the processor, other processes do not get the opportunity to set the program condition required for the first process to make progress. In a multiprocessor system, other processes execute on other processors and thereby modify the program state in order to release the first process from the spinlock. 12. (a) (1)P1 arrives at time 0 and is executed immediately. (2)P2 arrives at time 2 but is suspended because it is far from the deadline (remaining 12). (3)P3 arrives at time 3 and is more urgent than P2 (3<11), then is executed at time 3. (4)P4 arrives at time 5 and is more urgent than P2 (6<9), then is executed at time 5. (5)P5 arrives at time 8 and is more urgent than P2 (4<6), then is executed at time 10 but still misses the deadline (13>12). (6)P2 is executed at time 13 finally and is finished at time 16, so P2 misses the deadline. (7)The total scheduled order is P1 -> P3 -> P4 -> P5 -> P2. (b) P2 & P5 always miss the deadline. 13. (a) FCFS: SJF: Priority: RR: (b) FCFS完成時間分別為:P1 - 10、P2 - 39、P3 - 42、P4 - 49、P5 - 61,平均完成時間為: (10+39+42+49+61)/5=40.2。 SJF完成時間分別為:P1 - 20、P2 - 61、P3 - 3、P4 - 10、P5 - 32,平均完成時間為: (20+61+3+10+32)/5=25.2。 Priority完成時間分別為:P1 - 61、P2 - 29、P3 - 44、P4 - 51、P5 - 41,平均完成時間為: (61+29+44+51+41)/5=45.2。 RR完成時間分別為:P1 - 10、P2 - 61、P3 - 23、P4 - 30、P5 - 52,平均完成時間為: (10+61+23+30+52)/5=35.2。 (c) FCFS等待時間分別為:P1 - 0、P2 - 10、P3 - 39、P4 - 42、P5 - 49,平均等待時間為: (0+10+39+42+49)/5=28。 SJF等待時間分別為:P1 - 10、P2 - 32、P3 - 0、P4 - 3、P5 - 20,平均等待時間為: (10+32+0+3+20)/5=13。 Priority等待時間分別為:P1 - 51、P2 - 0、P3 - 41、P4 - 44、P5 - 29,平均等待時間為: (51+0+41+44+29)/5=33。 RR等待時間分別為:P1 - 0 、P2 - 32、P3 - 20、P4 - 23、P5 - 40,平均等待時間為: (0+32+20+23+40)/5=23。 (d) SJF具有最短平均等待時間(=13)。 14. (a) (1)mutual exclusion - If process Pi is executing in its critical section, no other processes can be executing in critical section. (2)progress - If no process is executing in critical section and there exist some processes wish to enter critical section, the selection of next processes entering critical section cannot be postponed indefinitely. (3)bounded waiting - The bound exists on the number of times other processes are allowed to enter their critical sections, after a process has made a request to enter critical section and before that request is granted. (b) The algorithm satisfies the requirements “mutual exclusion” and “bounded waiting”, but not for the “progress”. This algorithm is introduced by Dekker in 1965 and discussed as follows: (1) Mutual exclusion: None of process can enter critical-section without setting the flag. Each process checks the other process’s flag after setting its own. If both are set, the turn is used to allow only one process to proceed. That is turn = i or j, not both. (2) Progress: The turn is only considered when both processes are using, or trying to use, the critical-section is granted to whom own the turn. However, the algorithm omitted one statement after “While turn=j do no-op;” with “flag[i]=true”, it will make Pi has the chance to set its own flag to be true and enter critical-section immediately while turn<>j. Lack of the statement will make Pi unable to enter critical-section. Thus, it cannot satisfy the requirement “progress”. (3) Bounded waiting: The turn ensures alternate process entering critical-section when both are competing for access. After Pi exits critical-section, Pi makes “turn = j” and “flag [i]=false” immediately. Thus, it satisfy the requirement “bounded waiting”.
© Copyright 2025 Paperzz