Operating System Analysis: Starvation, Deadlock, Scheduling

Verified

Added on  2022/08/25

|25
|3830
|14
Homework Assignment
AI Summary
This assignment delves into the analysis of operating system scenarios, focusing on critical concepts such as starvation and deadlock. It explores priority scheduling algorithms, explaining how processes are prioritized and how starvation can occur, along with techniques like aging to mitigate it. The assignment then examines deadlock, discussing its causes, prevention methods, and the two-phase locking protocol. It further analyzes process scheduling by calculating waiting time and turnaround time using algorithms like Shortest Job First (SJF) and Longest Job First (LJF). Finally, the assignment includes a detailed scheduling timeline using First Come First Serve (FCFS) and Round Robin algorithms, providing a comprehensive understanding of how these algorithms manage processes within an operating system.
Document Page
Running head: ANALYSIS OF AN OPERATING SYSTEM SCENARIO
ANALYSIS OF AN OPERATING SYSTEM SCENARIO
Name of the Student
Name of the University
Author Note
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1ANALYSIS OF AN OPERATING SYSTEM SCENARIO
Table of Contents
Answer 1 - Handling Starvation......................................................................................................2
Answer 2 – Deadlock.......................................................................................................................4
Answer 3 – Waiting Time and Turnaround Time...........................................................................6
Answer 4 – Scheduling Timeline..................................................................................................10
Answer 5 - Deadlock reduction.....................................................................................................21
Bibliography..................................................................................................................................23
Document Page
2ANALYSIS OF AN OPERATING SYSTEM SCENARIO
Answer 1 - Handling Starvation
In Operating system the processes are sent to the CPU (Central Processing Unit) on a
basis of the priority of the processes. Here the priority of the processes decide which one will
execute first. The lowest the priority number assigned to a process has highest priority of getting
executed. This whole process is called Priority scheduling which the most widely used
algorithms in the current systems. For example suppose there are 3 processes named P1, P2 and
P3 are having priority 2, 1, 4 respectively, then the order of the processing will be P2, P1 and P3.
The scenario of the process scheduling is explained below with the burst time of the processes.
Process Burst time Priority
P1 10 2
P2 5 1
P3 8 4
P2 P1 P3
0 5 15 23
The Starvation is event in the Priority Scheduling where the Process is ready to be
executed, however; it is get stuck in a waiting queue due to arrival of new processes having
higher priority. The algorithm for the Priority scheduling (Preemptive and Non-preemptive both)
or Mutual Exclusion algorithms prevent the low priority process to ever get executed by the
CPU. Apart from the priority based algorithms the starvation can also be triggered in case of
Shortest Job first and longest job first. The scheduling algorithm, which is a part of the kernel,
allocates the resources to the processes equally. Deadlock is different than starvation as it
Document Page
3ANALYSIS OF AN OPERATING SYSTEM SCENARIO
happens when a resources is not free to use for a process which will eventually get free to use. In
process scheduling, if there presents any higher priority process P1 which depends on the other
priority P2’s result, then the process P1 never gets finished and the scenario of Starvation arises.
This scenario of starvation is also called as priority inversion. The lowest of the priority stays
alive and alive in the queue. It has observed in IBM 7094 at MIT that during a process
scheduling in 1967 submitted the record of execution of lowest priority processes in the year of
1973.
For preventing the Starvation, Aging technique is implemented in the OS. In this
technique the priority of the processes that waits in the queue to get executed, is gradually
increased. It means the number assigned to the priority gets decreased. For example the priority
ranged from high (0) to low (127), the priority of the processes get increased by 1 (decreasing the
priority number), on waiting every 15 minutes. It sums up to the thirty two hours maximum for
any 127 (low) process to reach the maximum priority. The lower priority gets higher in the aging
technique hence it prevents the situation where a process might never get executed.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
4ANALYSIS OF AN OPERATING SYSTEM SCENARIO
Figure 1: Priority-time graph
Now consider the previous scenario of the processes with an extra process P4. The aging
is implemented to prevention of any process starvation here.
Process Arrival time Burst Time Priority
P1 0 10 2
P2 1 5 1
P3 2 8 4
P4 3 17 2
Here, the process with high priority will get executed first according to the priority
scheduling. However after implementing the aging technique, suppose after 5 units of time the
priority will be increased of the lowest process. Here, the process P3 has the lowest priority and
Document Page
5ANALYSIS OF AN OPERATING SYSTEM SCENARIO
may never get executed. After 5 unit time and completion of P2 the priority of the P3 will
become 3. Now the P1 and P4 has same priority however the P1 will get executed first and then
the priority of P3 will become 1 after 10 units. Now the process P3 will have 1 priority and P4
will have 2. Hence, the priority of the P3 is higher now and it will execute first.
Answer 2 – Deadlock
a) Here the A locks the resource i which starts the growing phase of the 2-phase locking. Next
the Lock has been applied on the resource j. Next the i and j is updated.
for example
read(i);
i=i-50;
write i;
for second bank account,
read j;
j=j+50;
write j;
unlock(i);
unlock(j)
This transaction represents the transaction between two bank accounts, where the locked
resources are different and occurred in a serial way. Hence, there is no deadlock detected in the
system.
Document Page
6ANALYSIS OF AN OPERATING SYSTEM SCENARIO
b) If the number of accounts becomes dynamic rather than at a time there may be deadlock in
case of any transaction accessing a resource is required by another transaction. To prevent the
deadlock in transactions, there are four ways that are eliminating the mutual exclusions, hold and
wait, no preemption and circular wait. In case of the numbering request policy where each
resource will be assigned with a number for example R1, R2, R3….RN. The process can request
the resources in decreasing or increasing manner. For example if P2 is allocated for R2 then next
time it will request for the R3, R4…RN. Requesting number lesser than 2 may not be granted in
the system. This eliminates the circular wait of the resources in order to prevent the deadlock
situation.
Answer 3 – Waiting Time and Turnaround Time
Waiting time: The waiting time in Process scheduling is the time that required for a process to
get to the CPU after coming to the ready queue. It is calculated by subtracting the burst time
from turnaround time of a process.
Turnaround time: Turnaround time is the total time taken by a process in the system. It is
calculated by subtracting the arrival time of the process from the completion time of the process.
Calculating Waiting time and Turnaround time using Shortest Job first (SJF), and longest job
first (LJF).
(i) SJF
Process Arrival time Burst Time Priority
P1 0 10 2
P2 1 5 1
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
7ANALYSIS OF AN OPERATING SYSTEM SCENARIO
P3 2 8 4
P4 3 17 2
We will create the Gantt chart for SJF scheduling and then calculate the Total turnaround time =
completion time – arrival time and waiting time = turnaround time – burst time.
First at time 0 P1 in only available hence
P1
0 10
Now at the time 10, all other processes are ready in queue, however we will take the process
which have shortest burst time that is P2.
P1 P2
0 10 15
Again the P3 and P4 are ready where the smallest burst time of P3 will be executed next.
P1 P2 P3
0 10 15 23
P4 is left hence the final Gantt chart will become
P1 P2 P3 P4
0 10 15 23 40
Process Arrival
time
Burst
Time
Priority Completion
time
TAT Waiting
Time
Document Page
8ANALYSIS OF AN OPERATING SYSTEM SCENARIO
P1 0 10 2 10 10 0
P2 1 5 1 15 14 9
P3 2 8 4 23 21 13
P4 3 17 2 40 37 20
(ii) LJF
Process Arrival time Burst Time Priority
P1 0 10 2
P2 1 5 1
P3 2 8 4
P4 3 17 2
We will create the Gantt chart for LJF scheduling and then calculate the Total turnaround time =
completion time – arrival time and waiting time = turnaround time – burst time.
First at time 0 P1 in only available hence
P1
0 10
Now at the time 10, all other processes are ready in queue, however we will take the process
which have longest burst time that is P4.
P1 P4
Document Page
9ANALYSIS OF AN OPERATING SYSTEM SCENARIO
0 10 27
Again the P3 and P2 are ready where the longest burst time of P3 will be executed next.
P1 P4 P3
0 10 27 35
P2 is left hence the final Gantt chart will become
P1 P4 P3 P2
0 10 27 35 40
Process Arrival
time
Burst
Time
Priority Completion
time
TAT Waiting
Time
P1 0 10 2 10 10 0
P2 1 5 1 40 39 34
P3 2 8 4 35 33 25
P4 3 17 2 27 24 7
(iii) Priority Scheduling
Process Arrival time Burst Time Priority
P1 0 10 2
P2 1 5 1
P3 2 8 4
P4 3 17 2
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
10ANALYSIS OF AN OPERATING SYSTEM SCENARIO
We will create the Gantt chart for Priority scheduling and then calculate the Total turnaround
time = completion time – arrival time and waiting time = turnaround time – burst time.
First at time 0 P1 in only available hence
P1
0 10
Now at the time 10, all other processes are ready in queue, however we will take the process
which have highest priority that is P2.
P1 P2
0 10 15
Again the P3 and P4 are ready where the highest priority for P4 will be executed next.
P1 P2 P4
0 10 15 32
P3 is left hence the final Gantt chart will become
P1 P2 P4 P3
0 10 15 32 40
Process Arrival
time
Burst
Time
Priority Completion
time
TAT Waiting
Time
P1 0 10 2 10 10 0
P2 1 5 1 15 14 9
Document Page
11ANALYSIS OF AN OPERATING SYSTEM SCENARIO
P3 2 8 4 32 30 22
P4 3 17 2 40 37 20
Answer 4 – Scheduling Timeline
(i) FCFS (First Come First Serve)
Job Arrival Time CPU cycles required
A 0 4
B 3 7
C 5 3
D 9 15
E 12 1
We will no complete competition time, turnaround time (TAT) and waiting time to
develop the scheduled timeline for this algorithm.
Total turnaround time = completion time – arrival time and waiting time = turnaround
time – burst time.
Job Arrival
Time
CPU cycles
required (Burst
Time)
Completion
Time
TAT Waiting
time
A 0 4 4 4 0
B 3 7 11 8 1
C 5 3 14 9 6
chevron_up_icon
1 out of 25
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]