Page 1 of 8 ITEC202 Operating Systems, Midterm Exam Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC202 Operating Systems ITEC 202 Midterm Examination 31 January 2013, Thursday Duration: 85 Minutes Lecturer: Dr. Ahmet Rizaner Name Surname Student No Group General Remarks: 1. This is a closed book exam. 2. Attempt ALL questions. 3. Make sure you have 8 different pages including this page. 4. All work to be done in the spaces provided on the exam paper. 5. No books, notes and dictionaries are allowed. 6. You can use a calculator but mobile phones are not allowed to be used as calculators. 7. All mobile phones should be switched off during the exam. 8. If you think a question is not clear, then write the assumptions you made for your solution. Marks Question 1 (30 pts.) Question 2 (12 pts.) Question 3 (20 pts.) Question 4 (12 pts.) Question 5 (16 pts.) Question 6 (10 pts.) Total (100pts.) Good Luck
Page 2 of 8 ITEC202 Operating Systems, Midterm Exam Question 1. Multiple Choices (30 pts.) Choose only one best answer from the choices below for each question and write your answers to the space provided at the end of this section. (2 points each) 1. Which of the following transitions is likely to occur when an I/O operation for a process completes? a) Ready to Running b) Blocked to Ready c) Blocked to Running d) Running to Blocked 2. The Process Image element that contains the modifiable part of the user space is called the: a) Process Control Block b) System Stack c) User Data d) User Program 3. Which of the following can not be said about a process? a) Only one process can be running on any processor at any instant. c) A newly generated process will be in waiting state. b) Each process is represented in the OS by a PCB. d) A process is a program in execution. 4. Multiprogramming allows: a) Multiple processes to execute at exactly the same time. b) The OS to use the hardware more efficiently. c) Processes to run faster. d) Computer hardware to be more user friendly. 5. Process creation in a typical UNIX system is made by means of a kernel system call named. a) fork() b) run() c) CreateProcess() d) process() 6. The manages the processor s time by determining which application program is executed next. a) thread b) loader c) interrupt d) dispatcher 7. A Memory Table is an OS control structure that is used by the OS to: a) Manage I/O devices b) Manage processes c) Provide information about system files d) None of them 8. Which of the following is not an element of a process image? a) User data b) PCB c) User Program d) Thread state
Page 3 of 8 ITEC202 Operating Systems, Midterm Exam 9. is a 32-bit operating system with the ability to support older DOS and Windows applications. a) Windows 3.1 b) Unix c) Windows NT 3.1 d) MS-DOS 10. In MS-DOS, the DOS stands for. a) Direct Operating System b) Disk Operating System c) Dynamic Operating System d) Distributed Operating System 11. A architecture assigns only a few essential functions to the kernel, including address spaces, interprocess communication and basic scheduling. a) Monolithic kernel b) Microkernel c) Minikernel d) None of them 12. When one process spawns another, the spawning process is referred to as the process and the spawned process is referred to as the process. a) child - parent b) old - new c) parent child d) main - thread 13. consists of the most used and most fundamental components of the operating system. a) Processor b) Server c) Kernel d) Memory 14. Which of the following operating system does not support multithreading? a) Windows XP b) DOS c) Linux d) OS/2 15. Which of the following is not an advantage of symmetric multiprocessing architecture over uniprocessor architecture? a) Ability to evolve b) Performance c) Availability d) Incremental growth Answers of Question 1 Write your answers (A, B, C or D) for Question 1 into the spaces provided below. Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 b c c d a d d d Q9 Q10 Q11 Q12 Q13 Q14 Q15 c b b c c b a
Page 4 of 8 ITEC202 Operating Systems, Midterm Exam Question 2. Unix process creation (12 pts.) Consider the following section of the code and assume that all fork system calls are successful. main() { int j = 2; int pid; while (j >= 1) { pid = fork(); j=j-1; if (pid > 0) { } } printf("in parent %d. \n", j); } else { printf("in child %d. \n", j); } a. What value is returned if fork system call is not successful? (2 pts.) -1 b. What will be printed? (5 pts.) In parent 1. In parent 0. In child 1. In parent 0. In child 0. In child 0. (different outputs are possible) c. Draw a process tree for the above program. (5 pts.) A Parent B Child 1 C Child 2 D Child 3
Page 5 of 8 ITEC202 Operating Systems, Midterm Exam Question 3. Utilization (20 pts.) Assume there are three processes A, B and C. All processes are submitted for execution at the same time. The process A executes for 2 milliseconds then does I/O for 4 milliseconds then executes 3 millisecond then does I/O for 5 milliseconds more and then exists. The process B executes for 2 milliseconds then does I/O for 4 milliseconds then executes for 2 milliseconds more and then exits. The process C executes for 5 milliseconds then does I/O for 6 milliseconds and then exists. Assume no contention for the resources and the order of execution (priority) is A, B and C. a. Calculate the processor utilization with multiprogramming. (10 pts.) A I/O I/O I/O I/O I/O I/O I/O I/O I/O B I/O I/O I/O I/O C I/O I/O I/O I/O I/O I/O Overall I/O I/O I/O I/O I/O I/O Total Job Duration : 20 Utilization (%) Total Execution Duration : 14 b. Assume that the computer system has 1024 Mbytes of available memory. What is the memory utilization with multiprogramming if Process A requires 256 Mbytes, Process B requires 512 Mbytes and Process C requires 128 Mbytes of memory. Note that: all processes are submitted for execution at the same time. (6 pts.) Between 0-11ms A, B & C are in memory so total memory requirement is ( ) for 8ms. Between 11ms-14ms A & C are in memory so total memory requirement is ( ) for 3ms. Between 14ms-20ms only C is in memory so total memory requirement is ( ) for 6ms. The total memory utilization is : ( ) c. What would be the total job duration, if these processes were executed on a multi-processor system with two processors? (4 pts.) I/O I/O I/O I/O I/O I/O I/O I/O I/O I/O I/O I/O I/O I/O I/O I/O I/O I/O I/O 15 ms Total Job Duration : 15
Page 6 of 8 ITEC202 Operating Systems, Midterm Exam Question 4. Deadlock Research Allocation Graph (12 pts.) The current allocation, maximum needs (claims) and available resources are as shown below. A system is composed of four processes, {P1, P2, P3, P4}, and three types of consumable resources, {R1, R2, R3}. There are 2 units each of R1 and R3 and 1 unit of R2. P1 requests a unit of R1 and a unit of R3. P2 uses a unit of R1 and R3 and requests 1 unit of R2. P3 requests 1 unit each of R1 and R3. P4 uses a unit of R2 and requests a unit of R3. (a) Draw the resource-allocation graph. (6 pts.) (b) Is there any deadlock in this situation? Briefly Explain. Which if any of the processes are deadlocked in this state? What is a possible order of completion if no deadlock exists? (6 pts.) (a) the resource allocation grap is: R1 P1 P3 R2 P2 P4 R3 (b) NO! Although one cycle exist in the system P2 R2 P4 R3, There is a free resource of type R1 and R3. P1 and P3 can acquire one unit each of R1 and R3 and can finish. P4 can acquire one unit of R3 and can finish. P4 releases a unit of R2. Then P2 can acquire one unit of R2 and can finish. And so on. Hence there is no deadlock. Same possible safe orders are: P1 P3 P4 P2, P4 P2 P3 R1 etc.
Page 7 of 8 ITEC202 Operating Systems, Midterm Exam Question 5. Deadlock - Banker s Algorithm (16 pts.) A system that uses the Banker's Algorithm has six processes and four types of reusable resources (R1, R2, R3 and R4). The current allocation, maximum needs (claims) and available resources are as shown below. Allocation Matrix (A) Claim Matrix (C) Available Vector (V) Process R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4 P1 1 0 0 0 3 2 1 4 0 2 3 3 P2 1 2 2 0 1 4 5 2 P3 2 1 3 0 4 2 4 5 P4 1 4 1 0 6 6 1 0 P5 1 2 0 1 2 3 1 3 P6 1 4 3 1 2 4 4 1 Calculate the Needs matrix (Q) and then determine if this is a safe state? If so, give a sequence in which the processes can be serviced. If it is not a safe state then list the processes which are deadlocked. Show all your work and the content of available vector in each step clearly! First, P2 runs to completion then, V=[0 2 3 3] + [1 2 2 0] =[1 4 5 3] Next, P5 runs to completion then, V=[ 1 4 5 3]+ [1 2 0 1] =[2 6 5 4] Next, P1 runs to completion then, V=[ 2 6 5 4]+ [1 0 0 0] =[3 6 5 4] Next, P6 runs to completion then, Needs Matrix (Q) R1 R2 R3 R4 P1 2 2 1 4 P2 0 2 3 2 P3 2 1 1 5 P4 5 2 0 0 P5 1 1 1 2 P6 1 0 1 0 V=[ 3 6 5 4]+ [1 4 3 1] =[4 10 8 5] Next, P3 runs to completion then, V=[ 4 10 8 5]+ [2 1 3 0] =[6 11 11 5] Next, P4 runs to completion then, V=[ 6 11 11 5]+ [1 4 1 0] =[7 15 12 5] All processes can run to completion with these available recourses. The processes can be serviced as P2 P5 P1 P6 P3 P4; hence this is a safe state.
Page 8 of 8 ITEC202 Operating Systems, Midterm Exam Question 6. Process Synchronization Message Passing (10 pts.) Use message passing to synchronize processes A, B, C, D, and E so that process A must finish before B or C starts, process B must finish before D starts, process C and D must finish before E starts. Draw a diagram to represent the relations among processes. Use the notation send(mbox,msg) and receive(mbox,msg) to write your solution. The relations among processes can be represented in the following diagrams. A mbox 1 B mbox 2 D C mbox 3 E The program can be as follows: Process A: - do work of A send(mbox1, msga) /* Let B/C start */ send(mbox1, msga) /* Let B/C start */ Process B: read(mbox1, msga); /* Block until A is finished */ - do work of B send(mbox2, msgb); /* Let D start */ Process C: read(mbox1, msga); /* Block until A is finished */ - do work of C send(mbox3, msgc); /* Let C start */ Process D: read(mbox2, msgb) /* Block until B is finished */ - do work of D send(mbox3, msgd); /* Let E start */ Process E: read(mbox3, msgc); /* Block until C is finished */ read(mbox3, msgd); /* Block until D is finished */ - do work of E