CS3SH3 - Operating systems Name Mid-Term Winter 2017 Student No. Use of McMaster Standard Calculators allowed. Answer all questions on test paper. Use backs of sheets if necessary. This exam has 10 multiple choice questions and 4 descriptive type questions. Total Marks: 30 Time allotted: 50 minutes Multiple choice questions [10 marks] Circle your answer. Each question has just one correct answer. Therefore multiple selections will not get a mark. 1. True or False? The boot procedure is used to initiate a user program. (a) True (b) False 2. True or False? System calls are executed in kernel mode. (a) True (b) False 3. Consider the program below. What will be the output at LINE A. #include <sys/types.h> #include <stdio.h> #include <unistd.h> int value = 0; int main() { pid t pid; pid = fork(); if (pid == 0) { printf("CHILD: value = %d",value); /* LINE A /* return 0; } else if (pid > 0) { value = value + 5; printf("PARENT: value = %d",value);/* LINE B /* return 0; } } 1 (a) 0 (b) 5 (c) undefined (d) garbage value 4. Consider the program given in Question 3. What will be the output at LINE B. (a) 0 (b) 5 (c) undefined (d) garbage value of a process contains temporary data such as function pa5. The rameters, return addresses, and local variables. (a) text section (b) data section (c) program counter (d) stack 6. True or False? If the resource-allocation graph contains no cycles, then the system is in a deadlock state. (a) True (b) False 7. True or False? Short-term scheduler selects from among the processes in ready queue, and allocates the CPU to one of them. (a) True (b) False 8. True or False? The Shortest Job First (SJF) scheduling algorithm is provably optimal, in that it gives the minimum average waiting time for a given set of processes. (a) True (b) False 2 9. Suppose a program is operating with execution-time binding and the logical address generated is 200. The relocation register is set to 100. What is the corresponding physical address? (a) 199 (b) 201 (c) 200 (d) 300 10. Consider a physical memory of size 64MB. It is partitioned under the dynamic partitioning scheme. The operating system uses 8MB of memory space. At a given instance in time, below is the snapshot of memory: OS = 8MB P1 =16MB P2 =14MB 6MB P3 =18MB 2MB Process P4 = 8M B cannot be brought into memory because of (a) External Fragmentation (b) Not enough memory space (c) Compaction (d) Internal Fragmentation 3 Provide detailed answers to the questions below Provided your answers in the space provided below each question. If you need more space you can use the back side of the paper. Each question is for 5 marks. 1. Consider the below segment of code. (a) unique processes (including the parent) are created. (b) unique threads are created. (c) Draw the process tree for this code. int main() { Pid t pid1, pid2; pid1 = fork(); pid2 = fork(); if (pid1 = 0) { /* child pthread create(. . } if (pid2 > 0) { /* child pthread create(. . } } process */ .); process */ .); 4 2. Consider four concurrently running processes P1 , P2 , P3 , and P4 , with statements S1 , S2 , S3 , and S4 , respectively. S3 can only be executed after both S1 and S2 have been executed (the order in which statements S1 and S2 are executed is irrelevant.) Furthermore, S3 needs to be executed before S4 . Illustrate how you would use semaphores to synchronize these concurrent processes. 5 3. Consider a system with 5 processes P0 through P4 , and three resource types A (12 instances), B (8 instances) and C (5 instances). Snapshot of system at time T0 : P0 P1 P2 P3 P4 Max. Need A B C 9 6 2 5 4 3 3 1 2 6 2 3 1 0 4 Allocation A B C 4 4 1 1 2 0 2 0 2 3 1 0 0 0 2 Available A B C 2 1 0 Answer the following questions using the banker’s algorithm: (a) What is the content of the matrix Need? (b) Is the system in a safe state? If yes, provide a sequence of processes that shows that the system is in safe state. If no, explain why and list the processes involved in deadlock. (c) If a request from process P0 arrives for (2, 0, 0) at time T1 , can the request be granted immediately? Give a brief (possibly one line) explanation of your answer. 6 4. Consider a logical address space size of 232 bytes. Page size is 212 bytes and physical address space is 228 bytes. Compute the following: (a) Number of bits to represent logical address = (b) Number of bits to represent offset = (c) Number of pages = (d) Number of bits to represent a page number = (e) Number of frames = (f) Number of bits to represent a frame number = 7