Professional Documents
Culture Documents
BY QURAT UL AIN
CPU Scheduling
Preemptive Scheduling
In Preemptive Scheduling, the tasks are mostly assigned with their priorities.
Sometimes it is important to run a task with a higher priority before another lower
priority task, even if the lower priority task is still running. The lower priority task holds
for some time and resumes when the higher priority task finishes its execution.
Non-Preemptive Scheduling
In this type of scheduling method, the CPU has been allocated to a specific process. The
process that keeps the CPU busy will release the CPU either by switching context or
terminating. It is the only method that can be used for various hardware platforms.
That’s because it doesn’t need special hardware (for example, a timer) like preemptive
scheduling.
CPU Scheduling
Context switch
A context switch is a procedure that a computer's CPU (central processing unit)
follows to change from one task (or process) to another while ensuring that the
tasks do not conflict. Effective context switching is critical if a computer is to
provide user-friendly multitasking
What is saved in the Process Control Block?
In Multiprogramming, if the long term scheduler picks more I/O bound processes
then most of the time, the CPU remains idol. The task of Operating system is to
optimize the utilization of resources. If most of the running processes change
their state from running to waiting then there may always be a possibility of
deadlock in the system. Hence to reduce this overhead, the OS needs to schedule
the jobs to get the optimal utilization of CPU and to avoid the possibility to
deadlock.
The Purpose of a Scheduling algorithm
Gantt
Chart
First Come First Serve
Gantt
Chart P1
0 2
First Come First Serve
Gantt
Chart P1 P2
0 2 4
First Come First Serve
Gantt
Chart P1 P2
0 2 4 5
First Come First Serve
Gantt
Chart P1 P2 P3
0 2 4 5 8
First Come First Serve
Gantt
Chart P1 P2 P3 P4
0 2 4 5 8 12
First Come First Serve
Gantt
Chart P1 P2 P3 P4
0 2 4 5 8 12
First Come First Serve
Gantt
Chart P1 P2 P3 P4
TAT= CT-AT
0 2 4 5 8 12
First Come First Serve
Gantt
Chart P1 P2 P3 P4
WT = TAT-ET
0 2 4 5 8 12
First Come First Serve
Gantt
Chart P1 P2 P3 P4
WT = TAT-ET
0 2 4 5 8 12
Shortest Job Fist (SJF)
Gantt
Chart
Shortest Job Fist (SJF)
Gantt
Chart
0
Shortest Job Fist (SJF)
Gantt
Chart P3
0 1 3
Shortest Job Fist (SJF)
Gantt
Chart P3 P1
0 1 3 6
Shortest Job Fist (SJF)
Gantt
Chart P3 P1
0 1 3 6
Shortest Job Fist (SJF)
Gantt
Chart P3 P1 P2
0 1 3 6 10
Shortest Job Fist (SJF)
Gantt
Chart P3 P1 P2 P4
0 1 3 6 10 14
Shortest Job Fist (SJF)
Gantt
Chart P3 P1 P2 P4
0 1 3 6 10 14
Shortest Job Fist (SJF)
Gantt
Chart P3 P1 P2 P4
TAT= CT-AT
0 1 3 6 10 14
Shortest Job Fist (SJF)
Gantt
Chart P3 P1 P2 P4
WT = TAT-ET
0 1 3 6 10 14
Shortest Job Fist (SJF)
Gantt
Chart P3 P1 P2 P4
0 1 3 6 10 14
SJF Example