Module 2
Module 2
• It decides which task (or process) the CPU should work on at any
given time.
• CPU can only handle one task at a time, but there are usually
many tasks that need to be processed.
CPU and I/O Burst Cycle
• Process execution consists of a cycle of CPU execution and I/O wait.
• Process execution begins with a CPU burst, followed by an I/O burst, then
another CPU burst ... etc.
• The last CPU burst will end with a system request to terminate execution
rather than with another I/O burst.
- The dispatcher is responsible for loading the process selected by the Short-
term scheduler on the CPU (Ready to Running State) Context switching is done by the
dispatcher only.
3. Medium-Term Scheduler
Scheduling Criteria
• CPU utilization – keep the CPU as busy as possible.
• Instead, it waits till the process complete its CPU burst time
and then it can allocate the CPU to another process.
Types of Scheduling Algorithm
(a) First Come First Serve (FCFS)
(b) Shortest Job First (SJF)
(c) Round Robin (RR)Scheduling
(d) Priority Scheduling
First Come First Serve (FCFS)
Disadvantages
- It does not consider the priority or burst time of the processes.
- It suffers from convoy effect i.e. processes with higher burst
time arrived before the processes with smaller burst time.
Example 1
Q: Consider the following process with burst time (CPU execution time). Calculate
average turnaround time and average waiting time.
Solution for the Example 1 Contd..
Example 2
Q: Consider the processes P1, P2, P3 given in the below table, arrives for execution
in the same order, with Arrival Time 0, and given Burst Time,
Solution for the Example 2 Contd..
Example 3
Q: Consider the processes P1, P2, P3 given in the below table, arrives for execution
in the same order, with Arrival Time 0, and given Burst Time,
Priority Scheduling
• Out of all the available processes, CPU is assigned to the
process having the highest priority.
• The waiting time for the process having the highest priority
will always be zero in preemptive mode.
• The waiting time for the process having the highest priority
may not be zero in non-preemptive mode.
Advantages and Disadvantages
Advantages-
• It considers the priority of the processes and allows the important processes to run first.
• Priority scheduling in pre-emptive mode is best suited for real time operating system.
Disadvantages-
• Processes with lesser priority may starve for CPU.
• There is no idea of response time and waiting time.
Example:1
Contd…
Example : 2
Examples
Multiprocessor