CS 3530 - Operating Systems Test_1 - Sample Exercise Example: The following is the FCFS execution diagram given in the book for 5 processes P1 through P5, that have the following CPU Burst times in milliseconds respectively: 135, 102, 56, 148, 125. All processes arrive at 0ms. !!!!!!!!!!!!!!!!!!!!!!!!!!!!! Problem: Now you have just 3 processes, P1, P2 and P3, and they arrive at 1, 15 and 23 milliseconds respectively, and they each have two CPU Burst as follows (there are no I/O Bursts). P1: P2: P3: 10 5 7 3 12 2 For FCFS scheduling (a) complete the execution diagram, (b) calculate total waiting time for every process, and (c) calculate the average waiting time for all processes. (d) for RR scheduling with a time quantum of 5 milliseconds, (d) complete the execution diagram, (e) calculate total waiting time for every process, and (f) calculate the average waiting time for all processes. Example: The following is the SRT (Shortest Remaining Time) execution diagram given in the book for 6 processes P1 through P6, that have the following CPU Burst times respectively: 135, 102, 56, 148, 125, 65. All processes except P6 arrive at 0ms, and P6 arrives at 200ms. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Problem: Now you have 5 processes, P1 through P5, and they arrive at 1, 2, 4, 4 and 5 milliseconds respectively, and they have the following CPU Burst times respectively: 9, 8, 3, 10, 4. For SRT scheduling, (a) complete the execution diagram, (b) calculate total waiting time for every process, (c) calculate the average waiting time for all processes. Assume negligible context switch time. d) 1) Explain how priorities can be used in non-preemptive and preemptive scheduling. (2) List two examples. Problem: For the Batch System Model with Multiprogramming there are Processes P1, P2, and P3 that arrive at 2, 11, and 16 milliseconds respectively. The degree of multiprogramming is three. Each process has two CPU burst times as given in milliseconds: P1: 4 5 P2: 5 6 P3: 6 5 Each process has two I/O burst times as given in milliseconds: P1: 4 4 P2: 8 5 P3: 3 3 Assume that there is no delay time caused by context switching. Calculate the TOTAL wait time for P1, P2 and P3. If two processes are waiting at the same time, P1 takes precedence over P2 and P3, and P2 take precedence over P3. Extra credit: Calculate the total turnaround time required for each of the three processes. Using SRT (Shortest Remaining Time) scheduling, you have 5 processes, P1 through P5, that arrive at 0, 2, 4, 6 and 8 milliseconds respectively, and they have the following CPU Burst times respectively: 15, 10, 4, 9, 2. There are no I/O bursts. For SRT scheduling, (a) complete the execution diagram, (b) calculate total waiting time for every process, and c) calculate the average waiting time for all processes. Assume negligible context switch time. Calculate the total turnaround time required for each of the five processes. Deadlock –Banker’s Algorithm 1. A system has three resource types {A, B, C} and five processes {P1, P2, P3, P4, P5}. The total units of system resources are: (6, 10, 13). The maximum demands for every process are: P1(2,2,1), P2(3,7,4), P3(6,6,5), P4(4,3,5), P5(1,6,4). The current allocation is: P1 (0,0,1), P2 (2,0,0), P3 (1,0,3), P4 (2,3,5), and P5 (0,3,3). All this information is shown in the table below. (a) Fill in the NEED column shown below. (b) Is this state a safe state? Explain your answer by identifying a successful future sequence of processes that makes the state safe, or by explaining which processes are part of the problem that makes the state unsafe? Answer (3a) PROCESS P1 P2 P3 P4 P5 (3b) ALLOCATION A B C 0 0 1 2 0 0 1 0 3 2 3 5 0 3 3 MAX A B C 2 2 1 3 7 4 6 6 5 4 3 5 1 6 4 NEED A B C 2 2 0 Subtract (Allocation-Max) = need 1 7 4 5 6 2 2 0 0 1 3 1 Starting allocation is (5 6 12) subtract ( - ) Total Unit is (6, 10, 13) which leaves (1 4 1) as the available resources. It is a safe state because the following order of processes can work: The total system units are (6,10,13) or 6 resources for A, 10 for B, and 13 for C. And the current Allocation for P1 through P5 show a total current allocation of 5 for A, 6 for B and 12 for C: A B C 0 0 1 2 0 0 1 0 3 2 3 5 0 3 3 ------5 6 12 If you subtract (5,6,12) from total units of system resources (6,10,13) you get (1,4,1); Note: use (AVAILABLE := AVAILABLE – Request) Of all the processes, P1-P5, only P5 can use (1,4,1) to get to its MAX need, because P5 is at Allocated (0,3,3) and its MAX need is (1,6,4) and all it needs (Need Allocation – MAX) is (1,3,1) to get there, so it takes the (1,3,1) and (by subtracting available resources of (1,4,1) and (need) (1,3,1) is leaves (0,1,0). And so P5 goes first and then when it is totally finished, it releases the max resources it used, which was (1,6,4) and you add that to (0,1,0) and (by adding Allocation := Allocation + Request ti), Which is (1,6,4) +(0,1,0) your get (1,7,4). Then next P2 uses (2,0,0) and needs to go to (3,7,4) so it uses all the resources (1,7,4) and frees its (3,7,4) resources when done, leaving (3,7,4) available since it used all the resources. Then P4 or P1 can go because P4 needs (2,0,0) and (3,7,4) is available and P1 can go because it needs (2,2,0) and (3,7,4) is available. So in the case where P4 goes next, it uses (2,0,0) making it go to its max of (4,3,5) and leaving (1,7,4), and then when it is done, it frees its (4,3,5) and that adds to the (1,7,4) making (5,10,9) available for the next process, and so on. <P5, P2,P4,P1,P3> or <P5, P2,P4,P3,P1> or <P5, P2,P1,P4,P3> P5: P2: P4: P1: P3: Uses (1 3 1) and when done leaves (1 7 4) as the available resources Uses (1 7 4) and when done leaves (3 7 4) as the available resources Uses (2 0 0) and when done leaves (5 10 9) as the available resources Uses (2 2 0) and when done leaves (5 10 10) as the available resources Uses (5 6 2) and when done leaves (6 10 13) as the available resources Or: P5: P2: P4: P3: P1: Uses (1 3 1) and when done leaves (1 7 4) as the available resources Uses (1 7 4) and when done leaves (3 7 4) as the available resources Uses (2 0 0) and when done leaves (5 10 9) as the available resources Uses (5 6 2) and when done leaves (6 10 12) as the available resources Uses (2 2 0) and when done leaves (6 10 13) as the available resources Or: P5: P2: P1: P4: P3: Uses (1 3 1) and when done leaves (1 7 4) as the available resources Uses (1 7 4) and when done leaves (3 7 4) as the available resources Uses (2 2 0) and when done leaves (3 7 5) as the available resources Uses (2 0 0) and when done leaves (5 10 10) as the available resources Uses (5 6 2) and when done leaves (6 10 13) as the available resources CS 3530 – Operating Systems Test_1 - Review Topics Definition of an Operating System Linux commands been used with cs3 Stochastic Model Deterministic Model Processes Vs. Threads User Vs. Kernel Level Resources Types of Performance Models Performance Metrics Resource Capacity and Bottleneck Simple Batch Model Multiprogramming Multiprogramming Batch Model CPU and I/O Bursts Interrupts Context Switching Queues: Input, Ready, I/O Scheduling Policies Types of Schedulers Role of the Dispatcher Execution Diagrams Coordination between Processes / Processor Synchronization Definition of Critical Section Different types of Semaphores / Implementation Code Classical Synchronization Problems including Dining Philosophers Process Deadlock / Handling Deadlock Resource Allocation Graphs File Management Differences in File Systems Disk Scheduling Algorithms