lOMoARcPSD|14078901 Exam January 2015, questions Operating Systems (Newcastle University) StuDocu is not sponsored or endorsed by any college or university Downloaded by hfghfghfg gfhfghfgh (sidipiy703@hbehs.com) lOMoARcPSD|14078901 [CSC2025] NEWCASTLE UNIVERSITY SEMESTER 1 2014/2015 OPERATING SYSTEMS Time allowed - 1½ Hours Instructions to candidates: Answer ALL questions The total marks available for this exam are 100 Marks shown for sub-sections are indicative only [Turn Over] Downloaded by hfghfghfg gfhfghfgh (sidipiy703@hbehs.com) lOMoARcPSD|14078901 [CSC2025] Question 1 a) What are the two main functions of an operating system? [4 marks] b) Explain which of the following instructions should only be executed in kernel mode and which can be executed in user mode and why. i) Disable all interrupts ii) Read the time of day clock iii) Set the time of day clock iv) Change the value of a local variable [8 marks] c) What are the three main states of a process? Describe each state. With the use of a diagram, explain the transitions between process states. [13 marks] Question 2 a) Consider the following two lines of code: int ai[10]; int *pai = (int *) calloc(10, sizeof(int)); i) Explain the differences in memory allocation for ai and *pai. [8 marks] ii) Explain when the memory used by ai and *pai is available for reuse. [5 marks] b) Assuming there are system calls to fork and execute processes, describe the behaviour of an operating system shell by explaining the steps that the program repeats. You may use C language code, pseudocode, or English to describe a shell. [12 marks] Page 2 of 5 Downloaded by hfghfghfg gfhfghfgh (sidipiy703@hbehs.com) lOMoARcPSD|14078901 [CSC2025] Question 3 a) Consider a system of five jobs A to E with the following known run times and arrival times. Job Running time Arrival time A 2 minutes 0 minutes B 5 minutes 0 minutes C 3 minutes 3 minutes D 1 minutes 3 minutes E 2 minutes 3 minutes For the following two algorithms, calculate the length of time each job is in the system and the mean process turnaround time. Show your working out. i) First-come, first-served (assume alphabetic order for jobs with the same arrival time) [7 marks] ii) Shortest remaining time [8 marks] b) Consider a system with a high priority process H and a low priority process L. The processes share the same critical region. The processes use busy waiting to test whether they are able to enter the critical region. At one point in time, L is in the critical region and H becomes ready to run after completion of an I/O operation. i) If we apply the scheduling rule that the highest priority process must run whenever it is ready, what problem can occur? [5 marks] ii) Why does round robin scheduling avoid the problem with priority scheduling? [5 marks] Page 3 of 5 Downloaded by hfghfghfg gfhfghfgh (sidipiy703@hbehs.com) lOMoARcPSD|14078901 [CSC2025] Question 4 Consider the following incomplete pseudo-C code for a bounded buffer, buf, that is shared by producer and consumer processes. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #define SIZE 100 int buf[SIZE]; int start = 0; // index of first item int used = 0; // number of items in buf // declare semaphores void producer(void) { int item; while(true) { item = produce_item(); buf[(start + used) % SIZE] = item; used++; } } void consumer(void) { int item; while(true) { item = buf[start]; start = (start + 1) % SIZE; used--; consume_item(item); } } Assume produce_item is a function used by the producer to produce an item to put in buf and consume_item is a function used by the consumer to consume an item taken from buf. a) What are the constraints on access to the buffer that must be enforced to maintain its integrity? [5 marks] Page 4 of 5 Downloaded by hfghfghfg gfhfghfgh (sidipiy703@hbehs.com) lOMoARcPSD|14078901 [CSC2025] b) Assume that there is a library that defines a semaphore type and up and down operations on a semaphore. Either in modifications to the preceding code or in English language, explain how to use semaphores to maintain the integrity of the buffer. That is, in a modified program or in English, answer the following questions. i) What semaphores are required and what is their initial state? [9 marks] ii) What are the critical sections of producer and consumer code? [3 marks] iii) How are the semaphores used in the producer and consumer code? [8 marks] END Page 5 of 5 Downloaded by hfghfghfg gfhfghfgh (sidipiy703@hbehs.com)