**CSE 330**

**Operating
Systems**

**SAMPLE Mid
Term Exam **

*Open book, open notes. *

Q1 and Q2 are from Exam 1
material, Q3 and Q4 is from Exam 2 material

1]

There
are two identical processes being run on a system. Each process does the
following:

Executes a CPU burst of 1 sec.

Outputs 1 KByte of data

Executes a CPU burst of 1 sec.

Outputs 1 KByte of data

Executes a CPU burst of 1 sec.

Outputs 1 KByte of data

Executes a CPU burst of 1 sec.

Outputs 1 KByte of data

Executes a CPU burst of 1 sec and terminates.

A] If the output device has a
data rate of 1KByte/sec, find the turnaround time of each process under:

i] FIFO
scheduling (non-preemptive)

ii] Round Robin scheduling (assume the time quanta is small, and the exact
value is

not important.)

B] Now we add a output buffer of 10KBytes to the above system. Find the
turnaround time of each process under:

i] FIFO
scheduling (non-preemptive)

ii] Round Robin scheduling (assume the time quanta is small, and the exact
value is

not important.)

2]

It
is stated that the “Shortest Job First Policy” is optimal.

- What does optimal mean
in this context?
- What property of the
SJF policy is optimal and what property makes it not so desirable?
- Why do not use SJF?
- Prove that the SJF is
optimal with respect to the property in [B]

3]

The
following code fragment is a 2-process “solution” to the critical section
problem.

try[i] = true;

while (incs[j]) no-op;

while (turn=j and try[j]) no-op;

incs[i] =
true;

* critical section*

try[i] = false;

incs[i] =
false;

turn = j;

[2
- continued]

Does
the above “solution” meet all 3 conditions of critical sections? Please explain
your answer.

4]

There are 4 processes,
executing concurrently. Process P0 is in an infinite loop, incrementing the
value of the variable *x* (*x* is initialized to 0). P0 is the only
process that changes the value of *x*.

The rest of the processes P*i* (1 <= *i*<=3) monitor the value of *x*. Whenever *x* reaches a
value such that it is divisible by *i*, P*i* prints the
value of *x*. For example, P3 will
print the sequence 3 6 9 12 ….. as the value of *x* reaches 3, 6, 9, 12 and so on.

A] Write the code for all the 4
processes using semaphores. Note that P1 - P3 should be identical.

B] ~~Write the code for all the 4
processes using CCRs. Note that P1 - P3 should be identical~~.