logo资料库

北邮 操作系统期中考试试卷(含答案).docx

第1页 / 共6页
第2页 / 共6页
第3页 / 共6页
第4页 / 共6页
第5页 / 共6页
第6页 / 共6页
资料共6页,全文预览结束
北京邮电大学 2019——2020 学年第一学期 《操作系统》期中考试试题 1. FILL IN BLANKS ( 10 points, 须用英文应答,中文答对得一半分) (1) The device controller is responsible for moving the data between the peripheral devices that it controls and its local buffer storage. (2) Modern operating system is driven by interrupt . (3) If an attempt is made to execute a privileged instruction in user mode, the hardware does not execute the instruction but rather treats it as illegal and traps it to the operating system. (4) Considering OS interfaces, an application program can utilize system calls to acquire services provided by the OS. (5) Programs loaded into and executing in memory refers to process . It needs certain resources, including CPU, memory, files, and I/O devices to accomplish its task. (6) Three general methods used to pass parameters to the operating system are registers, memory block, and stack. (7) In When CPU executes the instructions of operating systems, it is said that CPU is in kernel / system / supervisor / privileged mode. (8) Two communication methods between processes are shared memory and message passing 。 (9) Operations on semaphores are initialization, wait() , and signal() 。 (10) 3 conditions that a good solution for critical section problems should satisfy are Mutual Exclusion, Progress , and bounded waiting. 2. CHOICE ( 10 points ) (1) D A.PCB is not included in the context of process? B. code C. kernel stack D. interrupt vector (2) Among the following migrations, A. runningready C. readyrunning D is impossible? B. runningwaiting D. waitingrunning (3) When does a process migrate from waiting state to ready state? C A. the process is waiting for an event C. event that the process is waiting for occurs D. time slice is used up B. process is selected by scheduler (4) _ B _is the interval from the time of submission of a process to the time of completion. A. Waiting time B. Turnaround time C. Response time D. Throughput (5) A starvation-free scheduling policy guarantees that no process waits indefinitely for service. Which of the following scheduling policies is starvation free? A. Round Robin C. Shortest Job First B. Priority D. None of the above A 1/6
(6) In multiprogramming system, in order to guarantee the integrality of shared variable, processes should enter their critical section mutual exclusively. Critical section refers to C A. a buffer C. a code segment B. a data segment D. synchronous mechanism . (7) A deadlock situation can arise if the four necessary conditions hold simultaneously in a system. Which one of the following is not the necessary conditions? C A. mutual exclusion B. hold and wait C. preemption D. circular wait (8) Which handling procedures of the following situations will not switch into monitor mode? A A. procedure calls B. system calls C. interrupts D. traps (9) In operating systems, the semaphore stands for instances of resource, it is a integer variable relevant to a queue ,its value can only be changed by operation wait() and signal(). If a semaphore S is initialized to 5, now it’s value is 2, how many processes is or are waiting in the queue relevant to S. D A. 3 C. 1 D. 0 B. 2 (10) In the following comments on processes and threads, only B are correct. ① As the result of I/O completion, a process switches from the waiting state to the ready state, and the CPU scheduling may take place. ② In a system with the operating system supporting kernel-level threads, the process is the basic unit for resources allocation, while the thread is the basic unit for CPU scheduling. ③ For several threads created by one process, one thread’s stack and registers can be shared by the others. ④ The round robin algorithm will never result in process starvation. ⑤ PCB contains the process state, the program counter, CPU registers, and user data. A. ① ② ③ C. ② ③ ⑤ B. ① ② ④ D. ② ④ ⑤ 3(. 12 points)In a system with 2 processors, there are 10 concurrent processes sharing a type of resource based on a semaphore S, (a) only one process is permitted to enter its critical section to use the resource, or (b) at most 3 processes are allowed to enter theircritical sections to use the resource, then answer the following questions. if each time, (1) in these two cases, what are the initial, maximum, and minimum values for the semaphore S respectively? Case (a) (b) initial value maximum value minimum value 1 3 1 3 -9 -7 (2) what are the maximum, and minimum numbers of processes in ready, running, and waiting state? number of processes ready running waiting maximum minimum 8 0 2 0 10 0 2/6
4.(10 points)In a computer system with only one processor, one input device and one printer. Processes A and B enter the system sequentially at time 0, and A is scheduled by the CPU scheduler at first. The execution tracks of A and B are as follows: A: CPU burst lasting 20ms, then I/O burst of 100ms on the input device, and then CPU burst lasting 50ms, exiting. B: CPU burst lasting 40ms, then I/O burst of 70ms on the printer, and then CPU burst lasting 30ms, exiting. (a) Suppose that preemptive SJF scheduling algorithm (SRTF) is employed, draw the Gantt chart to describe the resource usage of A and B on the CPU, the input device and the printer. (b) Calculate the waiting time and turnaround time for process A and Brespectively. Answer: (1) (2) for process A: waiting time: 30ms turnaround time: 200 ms for process B: waiting time: 20ms turnaround time: 160 ms 5.(20 points) Consider the following set of processes, their arrival time, CPU burst time, and priority numbers are as following. The length of the CPU burst given in millisenconds, and larger priority numbers imply higher priority. Process Arrival Time Burst Time Priority number 0 1 2 4 5 3 3 6 P1 P2 P3 P4 1 3 7 5 (1). Suppose that priority-based preemptive scheduling is employed, (a) Draw a Gantt chart illustrating the execution of these processes; (b) Calculate the average waiting time. (c) Calculate the average turnaround time. (2). Suppose that priority-based non-preemptive scheduling is employed, (a) Draw a Gantt chart illustrating the execution of these processes; (b) Calculate the average waiting time. (c) Calculate the average turnaround time. 3/6
(1) preemptive priority scheduling algorithms. (a) (b) the average waiting time: (c) the average turnaround time: (12+9+0+1)/4=5.5 (17+12+3+7)/4=9.75 (2) non-preemptive priority scheduling algorithms: (a) (b) the average waiting time: (c) the average turnaround time: (0+13+3+4)/4=5 (5+16+6+10)/4=9.25 4/6
6. (20 points ) There is a plate that can hold only one apple or can hold three oranges. Father put an apple once a time into the plate; mother put an orange once a time into the plate. If there is already one or two oranges on the plate, the mother can put another orange into the plate. Son takes an apple from the plate and eats. Daughter takes an orange from the plate once a time and eats. The processes for the father, mother, son, and daughter are shown as followings. In order to synchronize these processes, please design semaphores and complete these processes by using wait() and signal() operations on semaphores. (1) Define semaphores needed and initialize them. SEMAPHORES Splate=1; Sapple=0; Sorange=0; MUTEX_OC=1; MUTEX_MD=1; Orange_ROOM=3; Used to record the rooms left for keeping oranges. Used for mutual exclusion use of the plate. Used for synchronization between the process father and son. Used for synchronization between the process mother and daughter. Used for mutual exclusion operation on variable orange_count. Used for mutual exclusion operation on plate between mother and daughter. VARIABLE orange_count=0; Used to record the number of oranges kept in the plate. (2) Write appropriate code segmentation for each place marked by number from (1) to(8). Father: while(true){ (1) wait(Splate); (2) Put an apple into the plate; signal(Sapple); } Mother: while(true){ 5) wait(orange_ROOM); wait(MUTEX_OC); orange_count++; if (orange_count==1) wait(Splate); signal(MUTEX_OC); wait(MUTEX_MD); Put an orange into the plate; signal(MUTEX_MD); signal(Sorange); (6) } Son: while(true){ (3) wait(Sapple); Take the apple from the plate; signal(Splate); eats the apple; (4) } Daughter: while(true){ (7) wait(Sorange); wait(MUTEX_MD); Take an orange from the plate; signal(MUTEX_MD); (8) wait(MUTEX_OC); orange_count--; if (orange_count==0) signal(Splate); signal(MUTEX_OC); signal(orange_ROOM); eats the orange; } 5/6
7. (18 points) For the system described in the table below process Current allocation Maximum needs outstanding requests R1 2 1 0 0 P1 P2 P3 P4 R2 R3 R1 R2 R3 R1 0 0 2 0 0 1 0 1 0 5 4 0 1 2 2 1 0 0 1 1 2 2 1 2 R2 R3 1 0 0 1 0 0 0 0 Available R1 0 R2 2 R3 0 (1) How many instances are there for each type of resources? Total resources in the system are (R1, R2, R3) = (3, 5, 2), (2) Draw the resource-allocation graph (3) Is the system in a safe or unsafe state? Specify your judgingprocedure. System is in an unsafe state Need= R1 0 1 1 2 P1 P2 P3 P4 needs R2 0 3 3 0 R3 1 2 1 0 Resources available=(0, 2, 0) can not satisfy the requirements need from any processes, so there exists no safe sequence of processes, so system is in an unsafe state. (4) Is the system deadlocked? Specify your judging procedure. System is not deadlocked. According to deadlock detection algorithm, Work=(0,2,0) finish[i]=false for i=1,2,3,4 Because request3=(0,0,0)
分享到:
收藏