Adobe Scan 27-Nov-2024
Adobe Scan 27-Nov-2024
3. AGantt chart is a bar chart that provides a visual view of tasks scheduled
over time.
PO Pl P2 P3
16 22
Example:
Process ID Arrival Burst Time
Time Calculate the average wafting time and average Turnaround
P1 4 S time, if FCES Scheduling Algorithm is followed
P2 6
P3 3
P4 6 P3 P1 PS P2
P5 5 13 17 19
9
Gantt Chart The shaded box represents the idle time of CPU
Turn Around Time s Completion Time- Arrival Time
Waiting Time = Turn Around Tme - Burst Time
Process ID Arrival Time Burst Time Completion
Time
Turnaround
Time
Waiting Time
P1
9-4=5 5-5=0
P2 6 4 17 17-6-11 11-4=7
P3 3 3-0=3 3-3=0
P&
2 19-6=13 13-2=11
PS 5 4 13 13-5=8 8-4=4
Convoy Effect
1. FCFS algorithm is non-preemptive in nature, that is, once CPU time has been allocated to a
process, other processes can get CPU time only after the current process has finished. This
property of FCFS scheduling leads to the situation called Convoy Effect.
2. Convoy Effect is phenomenon associated with the First Come First Serve (FCFS) algorithm,
in which the whole Operating System slows down due to few slow pro cesses.
Hence in Convoy Effect, one slow process slows down the performance of the entire set of
processes, and leads to wastage of CPU time and other devices
Shortest-Job-First Scheduling:
1. This algorthm associates with each process the length of the process's next
CPUburst.
2 When the CPU is available, it is assigned to the process that has the
smallest next CPU burst.
3 This the best approach to minimize waiting time.
4. If the next CPU bursts of two processes are the same, FCFS scheduling is
used to break the tie.
5 A
more appropriate tem tor this scheduling method would be the shoreet
next- CPU-burst algorithm because scheduling depends on the leneth of
the next CPU burst of a process, rather than its total length.
Example:
P1
P2
P3
16-1z 15 15 -4
P2 16
P3 9-45 5-2 3
P4 6-06 6-6O
12 12-2 = 10 10 -3* 7
NoW.
" Average Turn Around ime (4 " 155+ 6" 10)/5 40/5 8una
" Average waiting ine (3 1+3+0+7) /5 24 15 4,8 unit
0 6 12 16
P4 P1 P3 P5 P2
Gentt Chart
If the arrival time for processes are different, which means allthe processes are not avalabe
in the ready queue at time 0, and some jobs arrive after some time, in such situation,
sometimes process with short burst time have to wait for the current process's executiOn to
on arrival of a process with short duration, the
finish, because in Non Pre-emptive SJF.
halted/stopped to execute the short job first.
existing job/process's execution is not
Scheduling (Preemptive)
Shortest Remaining Time First or Shortest Job First
Scheduling, jobs are put into ready queue as theyis
1 In Preemptive Shortest Job First time arives, the existing process
arrive,but as a process with short burst
shorter job is executed first.
preempted or removed fromn execution, and the
shortest job first scheduling is less than
2 The average waiting time for preemptive
FCFS scheduling.
both, non-preemptive SJF scheduling andShortest
also known as Remaining Time First, becausce at
3 The Pre-emptive SJF is executed frst. remaining time is
any given point of time, the job with the shortest
Example:SJF (Preemptive)
Consider the set of5 processes whose arrival time and burst time are given below
If the CPU scheduling policy is SJF preemptive, calculate the average waiting time and average turn around time.
Process Arrival Time Burst Time
Gantt Chart:
P? 1
P3 1 2 13 20
P4
6
P3 3 5 3
6 13
1
1
P3
PA
Priority Scheduling
with the highest priority.
1, Apriority is associated with each process, and the CPU is allocated to the process
2. Equal-priority processes are scheduled in FCFS order.
(predicted) next CPU hurst.
3. An SJF algorithm is simply a priority algorithm where the priority (p) Is the inverse of the
4. The larger the CPUburst, the lower the priority, and vice versa.
high priority. This difference
Note:Some systems use low numbers to represent low priority; others use low numbers for
can lead to confusíon.
1 We assume that low numbers represent high priority.
2 Priority scheduling can be either preemptive or nonpreemptive.
3 Apreemptive priority scheduling algorithm willpreempt the CPU if the priority of the newiy
arrived process is
higher than the priority of the currently running process.
queue.
4 Anonpreemptive priority scheduling algorithm will simply put the new process at the head of the ready
Example
In the Example, there are 7 processes P1, P2, P3, P4, PS, P6 and P7. Their prorit ies, Arriíval Titrea
nd burst time are given in the table.
7 6
7 10 7 10
We can prepare the Gantt chart according to the Non Pre-cmptive priority scheduling.
number 2. Since No
The Process Pl arrives at time 0 with the burst time of 3units and the priority
other process has arrived tillnow hence the OS will schedule it immediately.
Meanwhile the execution of PI. two more Processes P2 and P3 are arrived. Since the priority of
P3 is 3 hence the CPU willexecute P3over P2.
Meanwhile the execution of P3, All the processes get available in the ready queue. The Process
with the lowest priority number will be given the priority. Since P6 has priority number assigned
as 4 hence it will be executed just after P3.
After P6, P4 has the least priority number among the available processes; itwill get executed for
the whole burst time.
Since all the jobs are available in the ready queue hence Allthe Jobs willget executed according
to their priorities. If two jobs have similar priority number assigned to them, the one with the least
arrival tine will be executed.
P1 P3 P6 P4 P2 P5 P7
3 11 13 18 27 37
From the GANTT Chart prepared, we can determine the completion time of every process. The
turnaround time, waiting time and response time will be determined.
2 3 3
2 6 18 16 11
3 3 1 6 2
2 13 9
6 27 21 12
6 4 4 11 6 2
7 7 37 30
P1 \P2 P3
PA CPU Scheduler
Example:
Consider the set of 5 processes whose arrival time and burst time are
given below
Process ld Arrival time Burst time
P1
P2 1
P3
1
P4 3
P5
Gantt Chart
SuNet NutzrSng
Page Replacement Algorithms in Operating Systems
1. First In First Out (FIFO): This is the simplest page replacement algorithm. In this algorithm,
the operating system keeps track ofall pages in the memory ina queue, the oldest page is in
the front of the queue. When a page needs to be replaced page in the front of the queue s
selected for removal.
Example 1: Consider page reference string 1, 3,0. 3, 5, 6, 3with 3page frames.Find the number
of page faults.
Page 1, 3, 0, 3, 5,6, 3
reference
1 3 0 3 5 6
0 0 3
3 3 3 3 6 6
1 1 5 5 5
when 3 comes, it is already in memory so > 0 Page Faults. Then 5 comes, it is not available in
memory so it replaces the oldest page slot i.e 1. >1Page Fault. 6 comes, it is also not
available in memory so it replaces the oldest page slot i.e3>1Page Fault. Finally, when 3
come it is not available so it replaces 0 1page fault.
2.Optimal Page replacenment: In this algorithm, pages are replaced which would not be used
for the longest duration of time in the future.
Example-2: Consider the page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4 page
frame. Find number of page fault.
Page No. of Page frame - 4
reference 7,0.1,2,0,3.0 4.2,3,0,3,2,3
3 3 2 3
7 0 1 2 3 4 2
2 2 2 2
2 2 |2 2 2 2
1 1 4 4 4 4
1
0 0 0 0
7 7 3 3 3 3 3 3 3
2 3 0 4 2 3 3 2 3
7
2 2 2 2 2 2 2 2 2 2|
1 1 1 4 4 4| 4 4
0 0 0
7 3 3 3 3 3 3 3
Miss Miss Miss Hit Miss Hit Miss Hi Hit Hit Hit Hit Hit
Miss
Total Page Fault = 6
Here LRU has same number of page fault as optimal but it may differ according to question.
Initially, all slots are empty, so when 7 012are allocated to the empty slots ->4 Page faults
0 is already their so ->0 Page fault. when 3 camne it will take the place of 7because it is least
recently used>1 Page fault
Ois already in memory so >0Page fault.
AVOIdance is kind of futuristic in nature, By using strategy of"A voidance", we must assume.
We need to ensure that all information about resources which
process will need are known to
US pror to execution of the process. We use Banker'salgorithm toavoid deadlock.
2) Deadlock detection and recovery: Let deadlock occur, then do
occurred. pre-emption to handle t once
3) Ignore the problem altogether: Ifdeadlock is very rare, then let it happen and reboot the
system. This is the approach that both Windows and UNIX take.
Bankers Algorithm:
Suppose the number of account holders in a particular bank is 'n', and the total money in a bank is
"T. Ifan account holder applies for a loan; first, the bank subtracts the loan amount from full
cash and then estimates the cash difference is greater than T to approve the loan amount.
These steps are taken because if another person applies for a loan or withdraws some amount
from the bank, it helps the bank manage and operate all things without any restriction in the
functionality of the banking system.
Similarly, it works in an operating system. When a new process is created in a computer system,
the process must provide all types of information to the operating system like upcoming processes,
requests for their resources, counting them, and delays. Based on these criteria, the operating
system decides which process sequence should be executed or waited so that no deadkock occurs
in a system Therefore, it is also known as deadlock avoidance algorithm or deadlock detection in
the operating system.
Advantages
Following are the essential characteristics of the Banker's algorithm:
Disadvantages
It requires a fixed number of processes, and no additional processes can be started in the system
while executing the process.
while
The algorithm does no longer allows the processes to exchange its maximum needs
processing its tasks.
system.
Each process must know and state their maximum resource requirement in advance for the
When working with a banker's algorithm, it requests to know about three things:
How much each process can request for each resource in the system. It is denoted by the [MAX]
request.
How much cach process is currently holding each resource ina system. It is denoted by the
[ALLOCATED] resource.
It represents the number of cach resource currently available in the system. It is denoted by the
[AVAILABLE] resource.
Exampke:
433 210
P! 212 322
401 902
P3 020 753
P4 112 112
Solution:
1. The Cotent of the need matrix can be calculated by using the formula given below:
Nced = Max - Allocation
Process Need
L
A B C
Po 3 2
P
P 5
P: 7 3 3
P 0 2. Let us now check for the
safe state.
Safe sequence:
1 For process PO, Need =(3, 2, 1) and
Avaitabie--2,1,0)
3Fer Pee 2Need(5,6. I)
Avastabie (4, 2. )
Need c Avasiabie False
Availabje (4, 2, 2)
Need cAvailahie False
-(4, 2, 2}*0, 1, 2)
-(5, 3, 4) w, (New Availatsle)
6 Now agaui check kor Proves P2, Need (5,0, I)
Avaiiabie - (5, 3, 4)
- Available (9, 5, 5)
Need <= Available = True
The system allocates allthe needed resources to each process. So, we can say that the system
is ina safe state.
= [8 57] + [2 1 0] - [10 6 7]
An algorithm krown as the Ostrich algorithm ignores deadlocks. The operating system assumes no
chances of running intoa stalemate when using this method. It's comparable to howan ostrich will
bury its head in the ground and act as if nothing is wrong. This approach is employed when
preventing dcadkocks is expensive, and they don't happen often.
The Windows and Unix operating systems use this algorithm. Restarting the system resolves the
deadlocks.