0% found this document useful (0 votes)
14 views42 pages

Unit II I

The document outlines various CPU scheduling algorithms including FCFS, SJF, Priority Scheduling, and Round Robin, focusing on their advantages, disadvantages, and optimization criteria such as maximizing CPU utilization and throughput while minimizing waiting and turnaround times. It also discusses concepts like context switching, aging to prevent starvation, and processor affinity in multiprocessor systems. Additionally, it details the process management system calls that facilitate interaction between user-level programs and the operating system.

Uploaded by

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

Unit II I

The document outlines various CPU scheduling algorithms including FCFS, SJF, Priority Scheduling, and Round Robin, focusing on their advantages, disadvantages, and optimization criteria such as maximizing CPU utilization and throughput while minimizing waiting and turnaround times. It also discusses concepts like context switching, aging to prevent starvation, and processor affinity in multiprocessor systems. Additionally, it details the process management system calls that facilitate interaction between user-level programs and the operating system.

Uploaded by

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

Scheduling Criteria:

Maximize:
 CPU utilization: CPU utilization is the main task in which the
operating system needs to make sure that CPU remains as busy
as possible. It can range from 0 to 100 percent.
 Throughput: The number of processes that finish their execution
per unit time is known Throughput.
Cont.

Minimize
 Waiting time: Waiting time is an amount of time, that specific
process needs to wait in the ready queue.
 Response time: It is an amount of time in which the request was
submitted, the first response is produced.
 Turnaround Time: Turnaround time is an amount of time to execute
a specific process. The period between the time of process
submission to the completion time is the turnaround time.
Scheduling Algorithm Optimization
Criteria

 Max CPU utilization


 Max throughput
 Min turnaround time
 Min waiting time
 Min response time
FCFS CPU SCHEDULING-NP(non
pre-emptive)
 For the FCFS scheduling algorithm, read the number of processes/jobs in the system,
and their CPU burst times.
 The scheduling is performed on the basis of the arrival of the processes irrespective
of their other parameters.
 Each process will be executed according to its arrival.
 Calculate the waiting time and turnaround time of each of the processes accordingly.
 First come first serve (FCFS) scheduling algorithm simply schedules the jobs
according to the processes irrespective of their other parameters. The job which
comes first in the ready queue will get the CPU first.
 It is the easiest and most simple CPU scheduling algorithm. In this type of algorithm.
Characteristics of FCFS method:

• It offers non-preemptive scheduling algorithm.


• Jobs are always executed on a first-come, first-serve basis
• It is easy to implement and use.
Problems:
• FCFS leads to Convoy Effect, and hence poor resource
utilization and poor performance.
Convoy Effect is a phenomenon
associated with the First Come
First Serve (FCFS) algorithm, in
which the whole Operating
System slows down due to a
few slow processes

Convoy Effect is a situation


where many processes, that
need to use a resource for short
time are blocked by one process
holding that resource for a long
time.
Output of FCFS..
Calculating wt and tat

Waiting time
Wt[i]=bt[i-1]+wt[i-1]
For process p1
For process p3
Wt[1]=bt[1-1]+wt[1-1] Wt[3]=bt[3-
=bt[0]+wt[0]
=0+0 1]+wt[3-1]
=0
For process p2
=bt[2]+wt[2]
Wt[2]=bt[2-1]+wt[2-1] =2+10 =12
=bt[1]+wt[1]
=10+0
=10
Cont…

Turn around time Tat[2]=bt[2]+wt[2]

Tat[i]=bt[i]+wt[i] = 2+10 =12


Tat[3]=bt[3]+wt[3]
Tat[1]=bt[1]+wt[1]
= 6+12 =18
=10+0 =10
SJF CPU SCHEDULING

Shortest Job First is a non-preemptive AND pre-emptive scheduling algorithm in which the

process with the shortest burst or completion time is executed first by the CPU. That means

the lesser the execution time, the sooner the process will get the CPU. If two processes have

the same burst time, then First Come First Serve (FCFS) scheduling is used to break the tie.

 The pre-emptive mode of SJF scheduling is known as the Shortest Remaining Time

First scheduling algorithm.

 Best approach to minimize waiting time.


Advantages

 Results in increased Throughput by executing shorter jobs first,


which mostly have a shorter turnaround time.
 Gives the minimum average waiting time for a given set of
processes.
 Best approach to minimize waiting time for other processes
waiting for execution.
Disadvantages

 May lead to starvation as if shorter processes keep on


coming, then longer processes will never get a chance to
run.
 Time taken by a process must be known to the CPU in
advance, which is not always possible.
Starvation:

Starvation is the problem that occurs when high priority


processes (short-time processes) keep executing and low
priority processes get blocked for an indefinite time.
What is Aging in OS?

 In Operating systems, Aging is a scheduling technique used to avoid Starvation. Fixed


priority scheduling is a scheduling discipline in which tasks queued for utilizing a system
resource is assigned each priority. A task with a high priority is allowed to access a
specific system resource before a task with a lower priority is allowed to do the same.
 Aging is a technique of gradually increasing the priority (by time quantum) of processes
that wait in the system for a long time. By doing so, as time passes, the lower priority
process becomes a higher priority process.
 Aging is used to ensure that jobs with lower priority will eventually complete their
execution. This technique can be used to reduce the Starvation of low priority tasks.
example

Process Burst time


P3 P1 P2
name
P1 1 Process
name
Burs Waitin Turn
P2 5 t g time Around
time Time
P3 2
P3
1 0 1
P1
2 1 3
P2
5 3 8
Priority Scheduling

 For the priority scheduling algorithm, read the number of processes/jobs in the
system, their CPU burst times, and the priorities. Arrange all the jobs in order with
respect to their priorities.
 In Priority Preemptive Scheduling, the tasks are mostly assigned with their
priorities.
 Priority Scheduling is a method of scheduling processes that are based on
priority. In this algorithm, the scheduler selects the tasks to work as per the priority.
 The processes with higher priority should be carried out first, whereas jobs with
equal priorities are carried out on an FCFS basis.
Advantages

 Easy to use scheduling method.

 Processes are executed based on priority so high priority does not need to wait for long which
saves time.
 If two jobs having the same priority are READY, it works on a FIRST COME, FIRST SERVED
basis.
 In priority scheduling, a number is assigned to each process that indicates its priority level.

 Lower the number, higher is the priority.

 In this type of scheduling algorithm, if a newer process arrives, that is having a higher priority
Disadvantages

 If the system eventually crashes, all low priority processes get lost.

 If high-priority processes take lots of CPU time, then the lower


priority processes may starve.
 This scheduling algorithm may leave some low-priority processes
waiting indefinitely.
Calculation Process:

Proce Burs Waiti Turn priority


Proce Burst priority
ss t ng Around
ss time name time time Time
name P3 3 0 3 1
P1 5 3 P2 4 3 7 2
P2 4 2 P1 5 7 12 3
P3 3 1

P3 P2 P1
Round-Robin Scheduling Algorithm

 Round Robin is the preemptive process scheduling algorithm. Each process is


provided a fixed time to execute, it is called a quantum. Once a process is executed
for a given time period, it is preempted, and another process executes for a given time
period.
 This scheduling algorithm is one of the most popular scheduling algorithms which can
be implemented in most operating systems. The Algorithm focuses on Time Sharing.
In this algorithm, every process gets executed in a cyclic way. A certain time slice is
defined in the system which is called time quantum. Each process present in the
ready queue is assigned the CPU for that time quantum, if the execution of the
process is completed during that time, then the process will terminate else the
process will go back to the ready queue and waits for the next turn to complete the
execution.
Advantages

1. Round Robin Scheduling algorithm resides under the category of


Preemptive Algorithms.
2. This algorithm is one of the oldest, easiest, and fairest algorithms.
3. This Algorithm is a real-time algorithm because it responds to the event
within a specific time limit.
4. It is simple, easy to implement, and starvation-free as all processes get a
fair share of CPU.
Disadvantages

1. There is a Larger waiting time and Response time.


2. There is Low throughput.
3. There is Context Switches.
4. Gantt chart seems to come too big (if quantum time is less for
scheduling. For Example:1 ms for big scheduling.)
5. Time consuming scheduling for small quantum.
Context Switching

 Suppose that multiple processes are stored in a Process Control Block (PCB). One
process is running state to execute its task with the use of CPUs. As the process is
running, another process arrives in the ready queue, which has a high priority of
completing its task using the CPU. Here we used context switching which switches
the current process with the new process requiring the CPU to finish its tasks. While
switching the process, a context switch saves the status of the old process in
registers. When the process reloads into the CPU, it starts the execution of the
process when the new process stops the old process. If we do not save the state of
the process, we have to start its execution at the initial level. In this way, context
switching helps the operating system to switch between the processes and store or
reload the process when it requires executing its tasks.
Cont.…

 The Context switching is a technique or method used by the operating system to switch a
process from one state to another to execute its function using CPUs in the system. When
switching perform in the system, it stores the old running process's status in the form of
registers and assigns the CPU to a new process to execute its tasks. While a new process
is running in the system, the previous process must wait in a ready queue. The execution of
the old process starts at that point where another process stopped it.
There are three major triggers for context switching. These
are given as follows −

• Multitasking: In a multitasking environment, a process is switched out of the


CPU so another process can be run. The state of the old process is saved,
and the state of the new process is loaded. On a pre-emptive system,
processes may be switched out by the scheduler.
• Interrupt Handling: The hardware switches a part of the context when an
interrupt occurs. This happens automatically. Only some of the context is
changed to minimize the time required to handle the interrupt.
• User and Kernel Mode Switching: A context switch may take place when a
transition between the user mode and kernel mode is required in the
operating system.
Multiple Processor Scheduling

 Multiple processor scheduling or multiprocessor scheduling focuses on designing the


system's scheduling function, which consists of more than one processor.
 Multiple CPUs share the load (load sharing) in multiprocessor scheduling so that various
processes run simultaneously.
 Multiprocessor scheduling is complex as compared to single processor scheduling. In the
multiprocessor scheduling, there are many processors, and they are identical, and we can run
any process at any time.
 The multiple CPUs in the system are in close communication, which share a common bus,
memory, and other peripheral devices. So we can say that the system is tightly coupled.
 These systems are used when we want to process a bulk amount of data, and these systems
are mainly used in satellite, weather forecasting, etc.
 Multiprocessor systems may be heterogeneous (different kinds of CPUs)
or homogenous (the same CPU).
 There is no policy or rule which can be declared as the best scheduling
solution to a system with a single processor. Similarly, there is no best
scheduling solution for a system with multiple processors as well.
Approaches to Multiple Processor
Scheduling

 There are two approaches to multiple processor


scheduling in the operating system: Symmetric
Multiprocessing and Asymmetric Multiprocessing.
 Symmetric Multiprocessing: It is used where each
processor is self-scheduling. All processes may be in a
common ready queue.
 Asymmetric Multiprocessing: It is used when all the
scheduling decisions and I/O processing are handled by
a single processor called the Master Server. The other
processors execute only the user code. This is simple
and reduces the need for data sharing, and this entire
scenario is called Asymmetric Multiprocessing.
Processor Affinity

 Processor Affinity means a process has an affinity for the processor on


which it is currently running.
 systems try to avoid migrating processes from one processor to
another and keep a process running on the same processor. This is
known as processor affinity.
 There are two types of processor affinity
 Soft Affinity: When an operating
system has a policy of keeping a
process running on the same
processor but not guaranteeing it
will do so.
 Hard Affinity: Hard Affinity allows a
process to specify a subset of
processors on which it may run.
Process is a active entity as it is
Program is a passive entity as it resides in
2. created during execution and loaded
the secondary memory.
into the main memory.
Process exists for a limited span of
Program exists at a single place and
3. time as it gets terminated after the
continues to exist until it is deleted.
completion of task.

4. Program is a static entity. Process is a dynamic entity.

Process has a high resource


Program does not have any resource
requirement, it needs resources like
5. requirement, it only requires memory space
CPU, memory address, I/O during its
for storing the instructions.
lifetime.

Process has its own control block


6. Program does not have any control block.
called Process Control Block.

In addition to program data, a process


Program has two logical components: code also requires additional information
7.
and data. required for the management and
execution.
Process Scheduling Queues

 The OS maintains all PCBs in Process Scheduling Queues.


 The OS maintains a separate queue for each of the process
states and PCBs of all processes in the same execution state
are placed in the same queue.
 When the state of a process is changed, its PCB is unlinked
from its current queue and moved to its new state queue.
 The Operating System maintains the following important
process scheduling queues −
Job queue − This queue keeps all the processes in the system.
Contd..

 Ready queue − This queue keeps a set of all processes residing in the main
memory, ready and waiting to execute. A new process is always put in this
queue.
 Device queues − The processes which are blocked due to the unavailability of
an I/O device constitute this queue.
 The OS can use different policies to manage each queue (FCFS, SJF, Round
Robin, Priority).
 The OS scheduler determines how to move processes between the ready and
run queues which can only have one entry per processor.
Process Scheduling Queues
Process Management System Calls-
fork, exit, wait, waitpid, exec
 It acts as a link between the operating system and a process, allowing user-level
programs to request operating system services. The kernel system can only be
accessed using system calls.
 Process control is the system call that is used to direct the processes.
 Some process control examples include creating, load, abort, end, execute, process, terminate the
process, etc.
Functions:
• End and Abort
• Load and Execute
• Create Process and Terminate Process
• Wait

fork()
 Processes use this system call to create processes that are a copy of
themselves. With the help of this system Call parent process creates a
child process, and the execution of the parent process will be suspended
till the child process executes.
• A new process is created by the fork() system call.
• A new process may be created with fork() without a new program being
run-the new sub-process simply continues to execute exactly the same
program that the first (parent) process was running.
• It is one of the most widely used systems calls under process
management.
exit()
 The exit() system call is used to terminate program execution.
 The exit() system call is used by a program to terminate its execution.
 The operating system reclaims resources that were used by the process after the
exit() system call.
exec()
 A new program will start executing after a call to exec()
 Running a new program does not require that a new process be created first: any
process may call exec() at any time. The currently running program is immediately
terminated, and the new program starts executing in the context of the existing
process.
Exit(): This call indicates that the thread execution is complete, which is especially useful in
multi-threaded environments.
wait()
 In some systems, a process needs to wait for another process to complete its execution.
This type of situation occurs when a parent process creates a child process, and the
execution of the parent process remains suspended until its child process executes.
Waitpid():
 The waitpid() system call suspends execution of the current process until a child
specified by pid argument has changed state. By default, waitpid() waits only for
terminated children.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy