Solutions to Midterm 1

 

Q1. (a).

User Mode: User mode isolates the user program from the underlying system .The user programs cannot modify critical "system" data ,perform I/O operations etc.

Kernel mode: The kernel performs the important tasks such as memory management, process management , maintainence of the file system ,I/O operations etc.

The two modes are required in order to prevent malicious or inadvertent corruption of critical OS data structures and states.

(b)

In memory mapped I/O, ranges of memory addresses are set aside , and are mapped to the device registers. Read and Write operations to the memory addresses causes data to be transferred to or from the device registers.

Graphics related application benefit immensely from this approach.

(c )

In the layered approach , the operating system is broken into a number of layers , each built on the top of lower layers. The bottom layer is the hardware ; the highest layer is the user interface.

Advantage : Introduces Modularity, making system verification and debugging easier.

Disadvantage: Overhead introduced due to communication between the layers.

(d)

A deadlock is created when there are two or more processes each holding a resource, with each process requiring a resource held by the other process. Thus a cycle is created among the processes leading to a deadlock.

In case of starvation, a lower priority process doesn’t get access to a resource while the higher priority processes continuously use it. It is caused due to a defective scheduling algorithm.

Another difference is that no processes make progress when a deadlock occurs, while some processes make progress during starvation.

Q2.

  1. state transition diagram- refer AOS pg 89

A process cannot make a transition directly from a waiting to running . This is because the scheduler might have allocated the CPU to some other process. This will create problem for the scheduler. Hence process always enters the ready state before entering the running state. The scheduler then chooses among the processes which are in the ready state.

(b)

The primitives for message passing are send() and receive() .

The process Id is specified in order to correctly identify the intended sender and receiver.

(c )

void main ()

{

int PID, PID2;

PID = fork(); // create child

if (PID == 0)

{

// this is the child

PID2 = fork(); // create the grandchild

if (PID2 == 0)

{

// this is the grand child

printf ("I am the grand child !!!");

}

else waitpid(PID2) ;

exit(0);

} // if PID = 0

else

{

// this is the grandfather

waitpid (PID);

exit(0);

}

} // main

 

Q3.

(a)

In MLFQ scheduling , processes can move between queues. If a process uses it entire time slice ,it is moved to a lower priority queue. Processes that block before the time slice ends are moved to a higher priority queue.

Thus, processes with low execution times (typically I/O bound processes) can access the CPU earlier than processes with higher execution times(typically CPU bound processes).This behaviour is very much similar to that of the SJF scheduler.

Advantages:

  1. SJF requires the execution times of the processes apriori. MLFQ does not require this.
  2. In case of SJF, a job with large execution time may be starved by the continuous influx of smaller jobs. MLFQ ensures against starvation.

(b)

Completion TIME Wait Time

Job

Length

Arrival

Time

FCFS

RR

SRTF

FCFS

RR

SRTF

1

50

0

50

150

150

0

100

100

2

40

0

90

140

100

50

100

60

3

30

0

120

120

60

90

90

30

4

20

0

140

90

30

120

70

10

5

10

8

150

58

18

132

40

0

Wait time = completion time - length -arrival time

 

Q4.

(a)

Benefits of multiprogramming are independent of pre-emptive or non pre-emptive scheduling. In case of a non preemptive scheduler a thread may block for I/O. A different thread may then be scheduled. Thus a process which is threaded into a I/O thread and a CPU intensive thread will still have greater CPU utilization than a single heavyweight process.

 

Q5.

(a)

The given state is safe.

Refer lecture notes of lecture 12 (page 12) for the solution.

(b)

Initialization

Red = 1

Blue = Green = 0

MoveRed()

{

Red.wait();

Move;

Blue.signal;

}

Moveblue()

{

Blue.wait();

Move;

Green.signal;

}

 

 

Movegreen()

{

Green.wait();

Move;

Red.signal;

}