0% found this document useful (0 votes)
8 views8 pages

3 Osy

The document discusses different CPU scheduling algorithms including round robin, first come first serve, and shortest job first. It defines CPU and I/O burst cycles and explains conditions for deadlock and methods for deadlock prevention. Sample problems are provided comparing the scheduling algorithms using Gantt charts and calculating average waiting times.

Uploaded by

Niya Sankhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

3 Osy

The document discusses different CPU scheduling algorithms including round robin, first come first serve, and shortest job first. It defines CPU and I/O burst cycles and explains conditions for deadlock and methods for deadlock prevention. Sample problems are provided comparing the scheduling algorithms using Gantt charts and calculating average waiting times.

Uploaded by

Niya Sankhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

OPERATING SYSTEM 22516

Unit 4
2 MARKS
1) Define CPU and I/O burst cycle.
Ans:
CPU burst cycle: It is a time period when process is busy with CPU.
I/O burst cycle: It is a time period when process is busy in working
with I/O resources.

4 MARKS

1. .Describe I/O Burst and CPU Burst cycle with neat diagram. W-19
Ans :
CPU burst cycle: It is a time period when process is busy with CPU.
I/O burst cycle: It is a time period when process is busy in working
with I/O resources.
A process execution consists of a cycle of CPU execution and
I/O wait.
A process starts its execution when CPU is assigned to it, so
process execution begins with a CPU burst cycle.
This is followed by an I/O burst cycle when a process is busy
doing I/O operations.
A process switch frequently from CPU burst cycle to I/O burst cycle and
vice versa.
The complete execution of a process starts with CPU burst cycle,
followed by I/O burst cycle, then followed by another CPU burst
cycle, then followed by another I/O burst cycle and so on.
The final CPU burst cycle ends with a system request to terminate
execution.
2. Explain deadlock? What are necessary conditions for deadlock?
W-19
Ans:
In multiprogramming environment, several processes may compete for a finite
number of resources. A process requests resources and if the resources are not
available then the process enters into the waiting state. Sometimes a waiting
process is never again able to change its status because the resources requested
by it are held by other waiting processes. This situation is called as deadlock.
When a process request for resources held by another waiting process which in
turn is waiting for resources held by another waiting process and not a single
process can execute its task, then deadlock occurs in the system.
Example: Consider a system with three disk drives and three processes. When
each process request one disk drive, system allocates one disk drive to each
process. Now there is no more drive available in the system. If all three processes
request for one more disk drive, then all three processes will go into the waiting
state and system will go in deadlock state. Because any one process from the three

can execute only when one of them will release the disk drive allocated to it.
Necessary Conditions:
1. Mutual exclusion: At least one resource must be held in a non-sharable mode;
that is, only one process at a time can use the resource.
2. Hold and Wait: A process must be holding at least one resource and waiting to
acquire additional resources that are currently being held by other processes.
3. No pre-emption: Resources cannot be pre-empted i.e a resource can be released
only voluntarily by the process holding it.
4. Circular wait: A set {P0,P1…Pn} of waiting processes must exist such that P0
is waiting for a resource held by P1,P1 is waiting for a resource held by P2,…,Pn-
1 is waiting for a resource held by Pn and Pn is waiting for a resource held by P0.
Each process is waiting for the resources held by other waiting processes in
circular form.

3. Explain Round Robin algorithm with suitable example.W-19


Ans:
It is pre-emptive scheduling algorithm. A small unit of time known as a time
quantum or time slice is used for pre-emption of a currently running process.
Ready queue is implemented as a circular queue. CPU is assigned to the entire
processes one by one, on first come first serve basis, for a specific time period.
Every process executes for specified time period and CPU is given to the next
process when time quantum expires.
A new process is added at the tail of the ready queue when it enters
the system.
CPU scheduler selects first process from head of the ready queue and executes
it for a specified time quantum.
Once the time quantum expires, dispatcher is invoked to pre-empt current
running process and CPU is given to the next process placed at the head of the
ready queue. The running process may have a CPU burst time less or greater
than time quantum. If burst time of running process is less than the time
quantum then, the process itself releases the CPU. The scheduler then selects
next process from ready queue and executes it. If burst time of running process
is longer than time quantum then, context switch occurs and the process is place
at the tail of ready queue for remaining burst time execution.
Example:
Process Burst Time
P1 24
P2 3
P3 3
Time quantum: 4 ms
The resulting RR schedule is as follows:
CPU is allocated to process P1 for 4 ms. Since it requires another 20
milliseconds, it is preempted after the first time quantum and the CPU
is given to the next process in the queue, process P2. Process P2 does
not need 4 milliseconds, so it quits before its time quantum expires.
The CPU is then given to the next process, process P3. Once each
process has received 1 time quantum, the CPU returns to process P1
for an additional time quantum.

4. Describe conditions for deadlock prevention.W-22


Ans:
By ensuring that at least one of below conditions cannot hold, we can
prevent the occurrence of a deadlock.
1.Mutual Exclusion:
The mutual-exclusion condition must hold for non-sharable resources. Sharable
resources do not require mutually exclusive access, thus cannot be involved in a
deadlock.
2.Hold and Wait:
One way to avoid this Hold and Wait is when a process requests a
resource; it does not hold any other resources.
•One protocol that can be used requires each process to request and
be allocated all its resources before it begins execution.
•Another protocol that can be used is, to allow a process to request resources
only when the process has none. A process may request some resources and use
them. Before it requests any additional resources, it must release all the
resources that are currently allocated to it.
3.No Preemption:
If a process that is holding some resources requests another resource that cannot
be immediately allocated to it, then all resources currently being held are
preempted. That is these resources are implicitly released. The pre-empted
resources are added to the list of resources for which the process is waiting.
Process will be restarted only when all the resources i.e. its old resources, as
well as the new ones that it is requesting will be available.
4.Circular Wait
Circular-wait condition never holds is to impose a total ordering of all resource
types, and to require that each process requests resources in an increasing order
of enumeration.
Let R = {R1, R2, ..., Rn} be the set of resource types. We assign to each
resource type a unique integer number, which allows us to compare two
resources and to determine whether one precedes another in our ordering.
Formally, define a one-to-one function F: R _ N, where N is the set of natural
numbers.
5. Solve given problem by using SJF and FCFS scheduling
algorithm using Gantt chart. Calculate the average waiting time
for each algorithm. W-22

Waiting Time

P1=17
P2=3
P3=0
P4=10
Average waiting time=Waiting time of all processes / Number of processes
=(17+3+0+10) /4
=30/4
=7.5 milliseconds (ms)
Gantt Chart FCFS

Waiting Time
P1=0
P2=9
P3=16
P4=19
Average waiting time=Waiting time of all processes / Number of processes
=(0+9+16+19) /4
=44/4
=11 milli seconds (ms)

6. Solve given problem by using


(i) Pre-emptive SJF
(ii) Round Robin (Time Slice = 3 ms)
Calculate average waiting time using Gantt Char

Ans:
(i) Pre-emptive SJF:

Waiting Time= (Total completion time –Burst time ) – Arrival time


P11 –(17-8)-0 = 9ms,
P12- (5 – 4) -1 =0ms,
P13- ( 26-9)-2 =15ms,
P14- ( 10-5)-3 =2ms
Average waiting time :- (9+0+15+2)/4= 26/4=6.5 ms

(ii) Round Robin (Time Slice = 3 ms)

Waiting time: - P11 = (23-8)-0 =15ms,


P12-(16 – 4)- 1 =11ms,
P13-(26-9)-2 =15ms,
P14-(21-5)-3 =13ms
Average waiting time:- (15+11+15+13)/4=54/4= 13.5ms

You might also like