Exam Operating System FInal - Answer Scheme
Exam Operating System FInal - Answer Scheme
Test
2 |1
SECTION A
TRUE & FALSE QUESTIONS (10 MARKS)
(INSTRUCTION: Write your answer either TRUE (T) or FALSE (F) based on the following
statements.)
4. Race condition occurs when only one process try to access the global
variables.
[ T
9. In Round Robin scheduling if the time quantum is very large the scheduling
is the same as Shortest Remaining Time First (SRTF).
10. Shortest Job First (SJF) scheduling algorithm could result an aging.
T ]
SECTION B
2013/2014-2
Test
2 |2
QUESTION 1 [6 Marks]
a) Which of the followings are shared across threads in a multithreading process? Tick in the
appropriate boxes for your answer.
[2
marks]
Components
Program Counter
Address Space
Variables
State
Shared
Not Shared
/
/
/
/
[4
Marks]
QUESTION 2 [ 17 Marks]
a) Why do we need scheduling in operating system?
[1
Marks]
2013/2014-2
Test
2 |3
b) Consider the following set of processes in Table 1, with the length of the CPU-burst/cycle/time
given in milliseconds and the priority.
Table 1
Process
Arrival Time
CPU Cycle
Priority
i. Draw a timeline chart to illustrate the execution of the above processes using Priority scheduling
(preemptive) (smaller number implies higher priority).
[3 Marks]
ABDC
0 5 9 13 19
ii.
[4
Marks]
Table 2
Process
A
B
C
D
Waiting Time
Turnaround Time
Test
2 |4
iii.
Draw a timeline chart to illustrate the execution of the above processes using Shortest
Remaining Time (SRT).
[3
Marks]
iv.
Complete Table xx for the Shortest Remaining Time (SRT) scheduling. Show your
calculation.
[4
Marks]
Table 3
Process
A
B
C
D
Waiting Time
Turnaround Time
v.
[2
Marks]
2013/2014-2
Test
2 |5
[2
marks]
i.
Producer process
Produce information
ii.
Consumer process
Consume information
iii.
Unbounded- buffer
Unlimited buffer size
iv.
Bounded buffer
Fixed buffer size
[3 Marks]
2013/2014-2
Test
2 |6
d) Petersons Algorithm: Given a code for Process 0 and Process 1 in Table 4. Fill in flags and turn
variables if Process 1 initiates the request to enter the critical section.
[4 Marks]
Table 4
Process 0
Process 1
do {
do {
flag[0] = TRUE;
flag[1] = TRUE;
turn = 1;
turn = 0;
while (flag[1] && turn == 1)
while (flag[0] && turn == 0)
; /* do nothing */
; /* do nothing */
critical section
critical section
flag[0] = FALSE;
flag[1] = FALSE;
remainder section
remainder section
} while (TRUE);
} while (TRUE);
Table 5
tim
e
flag[0]
flag[1]
Turn
FALSE
TRUE
Events
P request to enter CS
1
2013/2014-2
Test
2 |7
t
t
t
t
t
t
1
2
3
4
5
6
t
t
FALSE
TRUE
P enters CS
1
TRUE
TRUE
P requests to enter CS
0
TRUE
FALSE
P executes RS
1
TRUE
FALSE
P enters CS
0
TRUE
FALSE
P executes RS
1
FALSE
FALSE
P executes RS
0
FALSE
FALSE
P executes RS
1
TRUE
FALSE
P requests to enter CS
0
[1 marks]
[1 marks]
[1 marks]
2013/2014-2
Test
2 |8
Producer
[6 marks]
Consumer
do {
do {
produce an item
wait(full);
wait(empty);
wait(mutex);
wait(mutex);
..
signal(mutex);
signal(mutex);
signal(empty);
signal(full);
} while (TRUE);
} while (TRUE);
Table 7
empty
mutex
full
Producer
wait( )
0
0
Consumer
wait( )
signal( )
1
1
empty
mutex
full
0
0
signal( )
1
1
i) If the initial value of empty is 0, what happen on the Producer side? Explain.
[2 Marks]
Producer cannot enter the critical section due to semaphore empty <=0. wait ( ) is not perform.
[2 Marks]
2013/2014-2
Test
2 |9
b) Based on the following sequence of statements for executing the three processes, state the output
for Table 8 to 11. Assume that all flags are initialized to 0.
[4 Marks]
Table 8
P0
wait(B_flag)
printf(B );
signal(C_flag)
P1
printf(A )
signal(B_flag)
P2
wait(C_flag)
printf(C )
Output : A B C
Table 9
P0
printf(B );
signal(C_flag)
P1
printf(A )
signal(B_flag)
P2
wait(C_flag)
printf(C )
Output : BCA/ABC/BAC
Table 10
P0
wait(B_flag)
printf(B );
signal(A_flag)
P1
wait(A_flag)
printf(A )
P2
printf(C )
signal(B_flag)
Output : CBA
Table 11
P0
wait(B_flag)
printf(B );
wait(C_flag)
P1
printf(A )
signal(B_flag)
P2
printf(C )
signal(C_flag)
Output : ABC/CAB/ACB
2013/2014-2
Test
2 | 10
2013/2014-2