Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

EASTERN MEDITERRANEAN UNIVERSITY

COMPUTER ENGINEERING DEPARTMENT


CMPE242 OPERATING SYSTEMS

MIDTERM I

Student No :………………… 14.11.2009

Name Surname :…………………

Group:…………………(Dr. Ahmet Ünveren Gr.1, Dr. Hakan Altınçay Gr. 2)

Q.1. A Q.1. B Q.2. Q.3. Q.4. Q.5. Total

Q.1. [10 pts]

A. Fill in the blanks of the following sentences:

a) Operating System controls and coordinates use of hardware among various applications
and users.

b) In simple batch systems, Spooling which refers to transferring input onto a temporary
working area to be later accessed by another program is used to improve performance.

c) In Symetric Multiprocessing each processor runs and identical copy of the operating
system which communicates with each other as needed.

d) In computer systems generally we have two communication models. With these models
communication may take place using either shared memory or message passing .

e) A process is a program in execution.

B. Specify whether the following statements are true or false.

a) The main advantage of distributed systems is that they allow shared memory model type
communication between processes. …F.

b) The next process to get CPU is selected using synchronization algorithm. ……F….

c) Two processes can not be in their running states at a given time. ……T..

d) Device controller informs CPU that it has finished its operation by causing an interrupt.
……T….

e) Hard disks and CD-ROMs are volatile storage mediums. …F…….


Q.2. [15 pts] Consider the following program:

Shared data
bool lock[2] = { false, false }; // In shared memory
int turn = 0; // In shared memory

Process Pi // i can be 0 or 1; process id


int other;
do{
other = 1 - i;
lock[i] = true;
while ( turn != i )
{
while ( lock[other] );
turn = i;
}
critical_section();
lock[i] = false;
remainder_section();
}while(true);

This is proposed as a software solution for synchronization of two concurrent processes.


Explain whether it satisfies all three requirements or not?
Solution:

1. Mutual exclusion is satisfied. While one process running in its CS other process should
wait in while (lock[other] ); loop.

2. Progress is satisfied. While one process running in its remainder section other process can
continue and go in its CS because of the lines:
while ( turn != i )
{
while ( lock[other] );
turn = i;
}

3. Bounded waiting is not satisfied because while one process waiting in while (lock[other] );
loop other process can go into its CS more than once
Q.3. [25 pts] Given the following table, how will these processes be scheduled using FCFS,
SJF and SRTF algorithms? Create a Gantt chart showing when each process will be
scheduled, and calculate the waiting times and turnaround times for the processes for each
scheduling algorithm.

Process CPU-Burst time Arrival time


P0 6 0
P1 2 3
P2 7 4
P3 1 7
P4 3 8

(FCFC) CPU Gantt Chart:

P0 P1 P2 P3 P4
0 6 8 15 16 19

(SJF) CPU Gantt Chart:

P0 P1 P3 P4 P2
0 6 8 9 12 19

(SRTF) CPU Gantt Chart:

P0 P1 P0 P3 P4 P2
0 3 5 8 9 12 19

W(P0) W(P1) W(P2) W(P3) W(P4)


FCFS 0 3 4 8 8
SJF 0 3 8 1 1
SRTF 2 0 8 1 1

tat(P0) tat(P1) tat(P2) tat(P3) tat(P4)


FCFS 6 5 11 9 11
SJF 6 5 15 2 4
SRTF 8 2 15 2 4
Q.4. [30 pts] Consider the following process arrival, CPU and I/O burst times. Assume that
only one I/O device is available and it operates using FCFS algorithm. Assume that there is
only one CPU and it uses SRTF algorithm.

Process Arrival time CPU I/O CPU


A 0 7 6 2
B 3 5 2 1
C 5 1 10 6

Draw the Gantt charts for the CPU and I/O device to compute the waiting time and
turnaround time (tat) of all processes and CPU utilization. Put your answers into the table
given below.

CPU Gantt Chart

A C A B C A B
0 5 6 8 13 16 22 24 25

I/O Gantt Chart

C A B
0 6 16 22 24

Wait(A) Wait(B) Wait(C) Tat(A) Tat(B) Tat(C) CPU


utilization
1 5 0 24 22 17 (22/25)x100%
Q.5. [20 pts]The processes A, B and C are synchronized as given below. Answer the
following questions by analyzing the given code. Assume that shared data may be used in
produceA, produceB and produceC parts of the programs.

Shared data:

Semaphore s1=0, s2=0;

Processs A: Process B: Process C:


{ { {

wait(s1); wait(s2);

//produceA; //produceB; //produceC;

signal(s1); signal(s2);

} } }

a) The execution can be in the order: first produceA, then produceB, then produceC.
……T…. (T/F)

b) A race condition may occur between process A and process C. ……F…. (T/F)

c) If the semaphore variables are initialized as s1=0 and s2=1, produceC, then produceB,
then produceA will be a possible sequence. ……F…. (T/F)

d) If the semaphore variables are initialized as s1=0 and s2=1, produceC, then produceA,
then produceB will be a possible sequence. ……T…. (T/F)

e) If the semaphore variables are initialized as s1=0 and s2=1, a race condition may occur
between process A and process C. ……T…. (T/F)

REMARK FOR Q.5.:

ANSWER THE PARTS THAT YOU ARE SURE. YOU WILL GET NEGATIVE GRADES FROM
WRONG PARTS

You might also like