操作系统代写: G6059 Operating Systems

Candidate Number

THE UNIVERSITY OF SUSSEX

BSc and MComp SECOND YEAR EXAMINATION May/June 2017 (A2)

Operating Systems

Assessment Period: May/June 2017 (A2)

DO NOT TURN OVER UNTIL INSTRUCTED TO BY THE LEAD INVIGILATOR

Candidates should answer TWO questions out of THREE. If all three questions are attempted only the first two answers will be marked.

The time allowed is TWO hours.

Each question is worth 50 marks.

At the end of the examination the question paper and any answer books/answer sheets, used or unused, will be collected from you before you leave the examination room.

G6059

G6059 Operating Systems

1. Process synchronisation.

  1. (a)  Name three different process synchronisation mechanisms, explain how theywork,anddiscusstheiradvantagesanddisadvantages. [15marks]
  2. (b)  Implement a simulation of the following road/railway traffic scenario. [35 marks]ABCD E

    Explanations:
    • The road has five sections: A, B, C, D and E.

    • A car driving from left to right is simulated by an instance of a thread CarLeftRight. A car driving from right to left is simulated by an instance of a thread CarRightLeft. You are given the methods void A(), void B(), void C(), void D(), void E() that simulate a car driving through the corresponding section of the road.

    • A train is simulated by an instance of a thread Train. You are given the methods void approach(), void cross(), void continue() that simulate a train approaching the road, crossing it, and continuing its way after the crossing, respectively.
    • Your implementation must enforce the following rules:
      • –  There must not be any collisions between cars and trains.
      • –  Section A can hold one car in each direction.
      • –  Section E can hold K cars in each direction.
      • –  Sections B, C and D can only hold a single car (regardless of the direction).
      • –  Only a single train can cross the road at a time.
      • –  Trains have priority over cars.
      • –  A car must not block the railway or deadlock while trying to pass.
      • –  You should maximise the number of cars driving on the road and the number of trains crossing the road.Consider the code template on the next page. You are expected to implement four code snippets (10–15 lines each). These code snippets replace the comments // my code n in the template (n ∈ {1,2,3,4}). You are not required to copy the template, but clearly label the start of each of your code snippets with the corresponding number n.

2

1 2 3 4 5 6 7 8 9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

Operating Systems

public class TrafficSimulation {

static final int K=50;
// initialize semaphores // my code 1

class CarLeftRight implements Runnable { void run() {

// my code 2

} }

class CarRightLeft implements Runnable { void run() {

// my code 3

} }

class Train implements Runnable { void run() {

// my code 4

} }

public static void main(String[] args) { // creates and starts threads…
// (no implementation required)

} }

The following class might be useful:

G6059

Class Semaphore
Semaphore(int permits, boolean fair)
Creates a Semaphore with the given number of permits
and the given fairness setting (fair=true).
void acquire()
Acquires a permit from this semaphore, blocking until one is available. void release()
Releases a permit, returning it to the semaphore.

3 Turn over/

G6059 Operating Systems

2. Scheduling, processes and threads.

  1. (a)  Name five goals pursued by scheduling algorithms, explain them and give application examples for each of them to illustrate their importance. [15 marks]
  2. (b)  Name three events that can cause a process switch. Give a concrete example for each of these events. [6 marks]
  3. (c)  Which operations are done by an operating system to perform a process switch? [10 marks]
  4. (d)  What is a microkernel? Which services does it provide? Discuss why you would (not) use a microkernel. [5 marks]
  5. (e)  Give an example of an application scenario where the use of threads is preferred to the use of processes. Give an example of an application scenario where the use of processes is preferred to the use of threads.

In both cases, justify your choice.
(f) Consider the following piece of C code:

1 int main(int argc, char∗∗ argv) {

  1. 2  fork ();
  2. 3  fork ();
  3. 4  return 0;

[10 marks]

5}
How many child processes are created upon execution of this program?

Justify your answer.

[4 marks]

4

Operating Systems G6059

3. Memory management, file systems and I/O.

  1. (a)  We will compare the number of page faults for the three page replacement strategies OPT, FIFO and LRU. For each of the three strategies fill in a table such as the one given as a template below.There are six pages: A, B, C, D, E, F. The header row contains the accesses to pages in the order from left to right. There are four page frames (the four rows 0, 1, 2, 3). The row PF is to mark a page fault. Discuss why the result confirms your expectations or why it does not. [30 marks]
  2. (b)  What is a block in a file system? Name three techniques for block allocation in a file system, and explain advantages and

A

B

C

D

B

E

D

F

C

E

B

F

A

F

E

D

F

A

0

1

2

3

PF

drawbacks.
(c) What is DMA? What is its advantage?

[16 marks] [4 marks]

5

End of Paper