Roll Number: Thapar University Patiala Computer Science & Engineering Department B.E 2 nd Yr. 1 st Semester CSE UCS303: Operating System MST, 19 th September 2017 Maximum Marks: 20 Time: 2 Hrs. Name of Faculty: Vinay, Tarunpreet, Ashish, Santosh, Raman Note: All Questions are Compulsory; Attempt in a SEQUENTIAL ORDER; Assume data from your side (if found missing). Q.1 a. Consider a system with the following set of processes, where arrival time and CPUburst time are in milliseconds. Compute the average turnaround time for the system taking pre-emptive shortest job first (SJF) algorithm. (2+2) Process Arrival Time Burst Time P 1 0 5 P 2 1 3 P 3 2 3 P 4 4 1 b. Consider three processes, all arriving at time zero, with total execution time (CPU and I/O) of 10, 20 and 30 units, respectively. Each process spends the first 20% of execution time doing I/O, the next 70% of time doing computation, and the last 10% of time doing I/O again. The operating system uses a SJF scheduling algorithm and schedules a new process either when the running process gets blocked on I/O or when the running process finishes its compute burst. Assume that all I/O operations can be overlapped as much as possible. For what percentage of time does the CPU remain idle? Q.2 a. Explain the role of MBR and POST in context of the steps that a computer follows after getting the power supply. (2+2) b. With a suitable diagram, comment on the statement, Multi-tasking is an expansion of multi-programming. Q.3 a. With a suitable depiction, explain multi-threading models. (2+2) b. List Pros and Cons of Microkernel-based architecture and Layered approach for designing an operating system. Q.4 a. Consider the following snapshot of a system with four processes A, B, C, and D. Compute the average waiting time for the Round Robin scheduling, where quantum is taken as 1ms. (2+2) Process A B C D Arrival Time (in ms) 0.000 2.001 3.001 3.002 CPU Burst (in ms) 4 7 2 2 b. Explain the statement with proper justification: In operating systems, the context switching represents a substantial cost to the system in terms of CPU time. P.T.O.
Q.5 Consider a system with 4 processes and 5 resource classes. At a particular time t 0, the snapshot for the various data structures involved in the system are as shown in the table below: Allocation MAX Available Process P 0 P 1 P 2 P 3 ABCDE ABCDE ABCDE 10211 11213 00X11 20110 22210 11011 21311 11110 11221 (4) a. Compute the smallest value of X for which the system is in safe state. Write the safe sequence too. b. After computing the values for X above, assume that a request of (00110) resources from P 3 arrives in the system. Describe by showing the values of various datastructures, the feasibility for granting the said request immediately. c. (This is in continuation of part b above) Now, comment on the feasibility for granting the request of (00001) resources initiated by P 0. d. Give the count for the total (maximum) available instances of all the resource classes present in the system. Solution 1: a) SOLUTIONS (TENTATIVE) b)
Marking Scheme for Solution 1 (Vinay Arora): a) GANTT Chart 0.5, Proper calculations for TAT 01, Final Avg. TAT 0.5 b) Matrix or Graphical representation for Burst Time / IO Time 01, Proper calculations for Idle time and total execution time 0.5, Percentage Idle time 0.5 Solution 2: a)
b) Multi tasking: Multitasking is the logical extension of multiprogramming.the concept of multitasking is quite similar to multiprogramming but difference is that the switching between jobs occurs so frequently that the users can interact with each program while it is running. This concept is also known as time-sharing systems. A time-shared operating system uses CPU scheduling and multiprogramming to provide each user with a small portion of time-shared system. Marking Scheme for Solution 2: a) Full form of MBR / correct description of MBR 1 mark Full form of POST / correct description of POST 1mark b) Description of time slices for making systems interactive in multi-tasking 1.5 marks Diagram showing switching between processes. 0.5 marks Solution 3: a)
b) Microkernal-based The main function of the microkernel is to provide a communication facility between the client program and the various services that are also running in user space. Communication is provided by message passing. For example, if the client program and service never interact directly. Rather, they communicate indirectly by exchanging messages with the microkernel. On benefit of the microkernel approach is ease of extending the operating system. All new services are added to user space and consequently do not require modification of the kernel. When the kernel does have to be modified, the changes tend to be fewer, because the microkernel is a smaller kernel. The resulting operating system is easier to port from one hardware design to another. Disadvantages in the microkernel exist however. A few examples are: Larger running memory footprint More software for interfacing is required, there is a potential for performance loss. Messaging bugs can be harder to fix due to the longer trip they have to take versus the one off copy in a
monolithic kernel. Process management in general can be very complicated. Layered-approach A system can be made modular in many ways. One method is the layered approach, in which the operating system is broken up into a number of layers (levels). The bottom layer (layer 0) id the hardware; the highest (layer N) is the user interface. The main advantage of the layered approach is simplicity of construction and debugging. The layers are selected so that each uses functions (operations) and services of only lower-level layers. This approach simplifies debugging and system verification. A final problem with layered implementations is that they tend to be less efficient than other types. For instance, when a user program executes an I/O operation, it executes a system call that is trapped to the I/O layer, which calls the memory-management layer, which in turn calls the CPU-scheduling layer, which is then passed to the hardware. At each layer, the parameters may be modified; data may need to be passed, and so on. Each layer adds overhead to the system call; the net result is a system call that takes longer than does one on a non-layered system. These limitations have caused a small backlash against layering in recent years. Fewer layers with more functionality are being designed, providing most of the advantages of modularized code while avoiding the difficult problems of layer definition and interaction. Marking Scheme for Solution 3: a) A bit about model with diagram and no explanation 1 mark; if appended with a bit of explanation 1.5 marks, whereas, with elaboration 2 marks. b) More than two pros cons of both the models 2 marks, Only two pros cons 1.5 marks, and with less than two pros cons 1 mark; 0.5 mark for giving just a general idea. Solution 4: a) b) Context switching indulge unnecessary time for saving and loading the context of processes that are needed
to be thrown out from the RAM and loaded into the RAM respectively. Marking Scheme for Solution 4: a) Gantt Chart 1 + waiting time 0.5 (each process) and avg. waiting time 0.5 (total 2 marks) b) Context switching 0.5+ why it incurs cost 1 + diagram 0.5 (total 2 marks) Solution 5: a) The smallest value is x = 2. The order of finishing is P 3 P 2 P 1 P 0 or P 3 P 2 P 0 P 1. Process Allocated Maximum Need P 0 P 1 P 2 P 3 ABCDE ABCDE ABCDE 10211 11213 01002 20110 22210 02100 11011 21311 10300 11110 11221 00111 FIRST, let us show that the problem is not safe when x = 1: only P 3 can finish. The available vector is now (1 1 2 2 1). But then no other process can finish. NEXT, if x = 2, then we can can again let P 3 finish first. Then the available vector is (1 1 3 2 1). Now Process P 2 can finish, and the available vector becomes (2 2 3 3 2). Now both P 1 or P 0 can finish (in either order). b) Can be granted immediately Process P 0 P 1 P 2 P 3 Allocated Maximum Need ABCDE ABCDE ABCDE 10211 11213 01002 20110 22210 02100 11011 21311 10300 11220 11221 00001 Available is 00101 The order of finishing is P 3 P 2 P 1 P 0 or P 3 P 2 P 0 P 1. c) New Available is 00101-00001=00100 Process Allocated Maximum Need ABCDE ABCDE ABCDE
P 0 P 1 P 2 P 3 10212 20110 11011 11220 11213 22210 21311 11221 01001 02100 10300 00001 Deadlock is there d) Max resources = 52653 Marking Scheme for Solution 5 (Tarunpreet Bhatia): a. 0.5 mark for X=2 and 0.5 mark for correct sequence P 3 P 2 P 1 P 0 or P 3 P 2 P 0 P 1. b. 0.25 mark for correct values of data structures Need, Allocation and Available, 0.25 mark for Yes request is feasible, 0.5 mark for showing safe sequence after the request is granted. c. 0.25 mark for request should not be granted, 0.75 mark for correct explanation as Available = 00100. d. 0.25 mark for first two correct entries A and B, 0.5 mark for C=6, 0.25 mark for correct values of D and E.