COURSE CODE: CPE 523
COURSE TITLE: ADVANCED OPERATING SYSTEMS
(b) Assume memory is allocated as specified in the Table below, beginning from left to right,
before additional requests for 20K, 10K, and 5K (in that order) are received. With a
corresponding resulting diagram, at what starting address will each of the additional
requests be allocated in the case of: First-fit, Best-fit, and Worst-fit?
Variable partition memory allocation
H
o
Used Hole Used Hole Used Used Hole Used Hole Used Hole
l
e
10k 10k 20k 30k 10k 5k 30k 20k 10k 15k 20k 20k
3 (a) Five processes A, B, C, D and E arrive in this order at the same time with the following
CPU burst and priority values. A smaller value means a higher priority
CPU Burst Priority
A 7 3
B 2 5
C 3 1
D 6 4
E 4 2
Fill the entries of the following table with waiting time and average waiting time for each
indicated scheduling policy and each process. Ignore context switching overhead.
Scheduling Policy Waiting Time Average
Waiting Time
A B C D E
First-Come-First-Served
Non-Preemptive Shortest-Job First
Priority
Round-Robin (time quantum=2)
(b) Explain Process Control Block? What are the information contained in a Process Control
Block?
4(a) What is deadlock? What are the necessary conditions for a deadlock to occur? List these
conditions and provide an elaboration.
Deadlock refers to a situation in which a set of two or more processes are waiting for other
members of the set to complete an operation in order to proceed, but none of the members is able
to proceed.
There are four necessary conditions:
1. Mutual Exclusion: Resources are not sharable. That is, the use of resources must be
mutually exclusive.
2. Hold and Wait: Processes hold some resources while waiting for additional ones.
3. No Preemption: Resources can only be released by processes voluntarily. They cannot
be preempted by the system.
4. Circular Waiting: A set of processes P1, P2, ... , Pn exits such that P1 is waiting for the
resources that are being held by P2; P2 is waiting for the resources that are being held by
P3; ...; and Pn is waiting for the resources that are being held by P1.
List three examples of deadlocks that are not related to a computer system environment.
Answer:
• Two cars crossing a single-lane bridge from opposite directions.
• A person going down a ladder while another person is climbing up the ladder.
• Two trains traveling toward each other on the same track.
• Two carpenters who must pound nails. There is a single hammer and a single bucket of nails.
Deadlock occurs if one carpenter has the hammer and the other carpenter has the nails.
(b) Draw a resource allocation graph and a resource allocation table for the following
scenario and determine whether the system is in a deadlock or not. Justify your answer.
P = {P1, P2, P3}
R = {R1, R2, R3, R4}
No. of instances of R1, R2, R3 and R4 are 1, 2, 1 and 3 respectively.
E = {P1 → R1, R1 → P2, R2 → P1, R2 → P3, P2 → R3, P2 → R2, R3 → P3,
R4 → P3}
Resource allocation graph
Resource allocation Table
Proc Current Outstanding Resources
ess Allocation Requests Available
2
R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4
P1 0 1 0 0 1 0 0 0
P2 1 0 0 0 0 1 1 0 0 0 0 2
P3 0 1 1 1 0 0 0 0
P3 can complete as it is not waiting for any resource. This releases R2 and R3 which will be available to
P2 and it completes, followed by R1 available for P1 and it completes. A reduced resource allocation
graph with no arcs means there is no deadlock. Therefore, system is not in a deadlock.
An OS contains 3 resource classes. The number of resource units in these classes is 7, 7 and 10,
respectively. The current resource allocation state is as shown below:
(i) Is the current allocation state safe?
(ii) (ii) Would the following requests be granted in the current state?
• Process 1 p requests (1, 1, 0)
• Process 2 p requests (0, 1, 0)
• Process 3 p requests (0, 1, 0)
3
5(a) Name the scheduler responsible for:
(ii) swapping out partially executed programs
(iii) controlling the degree of multiprogramming
(iv) shifting a process from ready state to running state
(v) selecting a proper mix of CPU bound and I/O bound processes
(b) On a system with 1Mb of memory using the buddy system, draw a diagram showing the
allocation of memory after each of the following events.
i. Process A, request 150k
ii. Process B, request 100k
iii. Process C, request 50k
iv. Process B, exit
v. Process D, request 200k
vi. Process E, request 60k
vii. Process C, exit
viii. Process A, exit
ix. Process E, exit
x. Process D, exit
The buddy memory allocation technique is a memory allocation algorithm that divides memory into
partitions to try to satisfy a memory request as suitably as possible. This system makes use of splitting
memory into halves to try to give a best fit.
4
5
At some point in time, the following holes (in the order) are created by a variable partition of
memory. 20K, 15K, 40K, 60K, 10K, 25K. For a new process of 25 K, which hole would be filled
using best fit, first fit, and worst fit?
For 25 K using best fit the hole of 25 K is preferred. For first fit, 40 K is preferred and for worst
fit 60K is preferred
Given memory holes (i.e., unused memory blocks) of 100K, 500K, 200K, 300K and 600K (in
address order) as shown below, how would each of the first-fit, next-fit, best-fit and worst-fit
algorithms allocate memory requests of 290K, 420K, 110K and 350K (in this order)?
In the first fit approach is to allocate the first free partition or hole large enough which can
accommodate the process. It finishes after finding the first suitable free partition.
The best fit deals with allocating the smallest free partition which meets the requirement of the
requesting process. This algorithm first searches the entire list of free partitions and considers the
smallest hole that is adequate. It then tries to find a hole which is close to actual process size needed.
In worst fit approach is to locate largest available free portion so that the portion left will be big enough
to be useful. It is the reverse of best fit
6
Given memory partitions of 100K, 500K, 200K, 300K, and 600K (in order), how would each
of the First-fit, Best-fit, and Worst-fit algorithms place processes of 212K, 417K, 112K
and 426K (in order)? Which algorithm makes the most efficient use of memory?
First-fit:
• 212K is put in 500K partition
• 417K is put in 600K partition
• 112K is put in 288K partition (new partition 288K = 500K - 212K)
• 426K must wait
Best-fit:
• 212K is put in 300K partition
• 417K is put in 500K partition
• 112K is put in 200K partition
• 426K is put in 600K partition
Worst-fit:
• 212K is put in 600K partition
• 417K is put in 500K partition
• 112K is put in 388K partition
• 426K must wait
(1mk each = 12mks)
Best-fit algorithm turns out to be the best. (2mks)
Name the scheduler responsible for:
(i) swapping out partially executed programs- medium term scheduler
(ii) controlling the degree of multiprogramming- long term scheduler
(iii) shifting a process from ready state to running state- short term scheduler
(iv) selecting a proper mix of CPU bound and I/O bound processes- long term scheduler
Consider the following set of processes, with the length of CPU burst time given in milliseconds:
(i) Draw Gantt charts illustrating the execution of these processes using (1) FCFS (2) Preemptive SJF
or SRJF (3) Non preemptive priority based (4) round robin with time quantum = 2
7
(ii) What is the average waiting time of each of the scheduling algorithms given in part (i)?
Following is the snapshot of a CPU
Draw the Gantt chart and calculate the turnaround time and waiting time of the jobs for FCFS (First
Come First Served), SJF (Shortest Job First), SRTF (Shortest Remaining Time First) and RR (Round Robin
with time quantum 10) scheduling algorithms.
8
9