Upload
atish-kedia
View
68
Download
1
Embed Size (px)
DESCRIPTION
process scheduling in operating systems
Citation preview
CPU Scheduling CPU Scheduling
Process Scheduling is process of Process Scheduling is process of deciding CPU is assign to which process deciding CPU is assign to which process
There are two types of CPU There are two types of CPU Scheduling AlgorithmsScheduling Algorithms
1. Preemptive Scheduling1. Preemptive Scheduling 2. Non preemptive Scheduling 2. Non preemptive Scheduling
Non Preemptive Non Preemptive Scheduling Scheduling
In this method once the CPU has been In this method once the CPU has been allocated to a process ,the process allocated to a process ,the process keeps the CPU until it release the keeps the CPU until it release the CPU either by terminating or switching CPU either by terminating or switching to the waiting state to the waiting state
Preemptive Scheduling Preemptive Scheduling
In this method take the CPU forcibly In this method take the CPU forcibly from one process and assign to from one process and assign to another process another process
CPU scheduling decision depending on CPU scheduling decision depending on the following four circumstances the following four circumstances
1. when a process switches from the 1. when a process switches from the running state to the waiting staterunning state to the waiting state
2. when the process switches from running 2. when the process switches from running state to the ready statestate to the ready state
3. when the process switches from waiting 3. when the process switches from waiting state to the ready state state to the ready state
4. when a process terminates 4. when a process terminates
Scheduling Criteria Scheduling Criteria
CPU scheduling depending the CPU scheduling depending the following criteria's following criteria's
1.1. CPU Utilization CPU Utilization 2.2. Throughput Throughput 3.3. Turnaround TimeTurnaround Time4.4. Waiting TimeWaiting Time
Non Preemptive Non Preemptive Scheduling Scheduling
1.1. FCFS (First Come First Served)FCFS (First Come First Served)2.2. SJF ( Shortest Job First)SJF ( Shortest Job First)3.3. Priority Scheduling Priority Scheduling
FCFS FCFS
In this Schema the process that In this Schema the process that requests the CPU first is allocated the requests the CPU first is allocated the CPU first CPU first
The implementation of FCFS based on The implementation of FCFS based on FIFO queueFIFO queue
Consider the following set of processes Consider the following set of processes that arrive at time 0, with the length of that arrive at time 0, with the length of the CPU burst time given in the CPU burst time given in milliseconds milliseconds
Process Process Burst Time Burst Time p1 24p1 24 p2 3p2 3 p3 3p3 3
p1 p2 p3
0 24 27 30
Consider the following set of processes Consider the following set of processes that arrive at time 0, with the length of that arrive at time 0, with the length of the CPU burst time given in the CPU burst time given in milliseconds milliseconds
Process Process Burst Time Burst Time p1 6p1 6 p2 8p2 8 p3 7p3 7 p4 3p4 3
Priority Algorithm Priority Algorithm
In this technique a priority is In this technique a priority is associated with each process and the associated with each process and the CPU is allocated to the process with CPU is allocated to the process with highest priority highest priority
If two processes are having equal If two processes are having equal priority processes are scheduled priority processes are scheduled based on FCFS based on FCFS
Consider the following set of processes Consider the following set of processes that arrive at time 0, with the length of that arrive at time 0, with the length of the CPU burst time and priorities are the CPU burst time and priorities are given in below given in below
Process Process Burst Time Priority Burst Time Priority p1 10 3p1 10 3 p2 1 1p2 1 1 p3 2 3p3 2 3 p4 1 4p4 1 4 p5 5 2p5 5 2
p2 p5 p1 p3 p4
0 1 6 16 18 19
TAT Wait Time
P1
P2
P3
P4
p5
16-0=16
1-0=1
18-0=18
19-0=19
6-0=6
16-10=6
1-1=0
18-2=16
19-1=18
6-5=1
Preemptive algorithmsPreemptive algorithms
Preemptive SJFPreemptive SJF Preemptive PriorityPreemptive Priority Round Robin Round Robin
Preemptive SJFPreemptive SJFThis technique depending on two This technique depending on two
conditioncondition1. When new job enter into ready queue1. When new job enter into ready queue check the CPU burst time of new job check the CPU burst time of new job
with the remaining CPU burst time of with the remaining CPU burst time of the Current jobthe Current job
case 1: if the CPU burst time of new job case 1: if the CPU burst time of new job less than remaining CPU burst time of less than remaining CPU burst time of the current job CPU suspend the the current job CPU suspend the current job temporarily and take new current job temporarily and take new job for executionjob for execution
Case 2: if the remaining CPU burst time of Case 2: if the remaining CPU burst time of current job is less than or equal to new job current job is less than or equal to new job
then the CPU continues execution with then the CPU continues execution with the current job the current job
2. When job terminate2. When job terminate
Consider four jobs along with CPU burst Consider four jobs along with CPU burst time and arrival time time and arrival time
Process Process Burst Time Arrival Time Burst Time Arrival Time j1 5 0j1 5 0 j2 2 2 j2 2 2 j3 1 3j3 1 3 j4 3 5j4 3 5
j1 j2 j2 j3 j1 j4
0 2 3 4 5 8 11
TAT Wait Time
j1
j2
j3
j4
8-0=8
4-2=2
5-3=2
11-5=6
8-5=3
2-2=0
2-2=0
6-3=3
Round Robin Algorithm Round Robin Algorithm
Round Robin designed for time Round Robin designed for time sharing systemssharing systems
In this technique each process assign In this technique each process assign certain time quantum or time slice at certain time quantum or time slice at all timeall time
The time quantum ranges from 10 to The time quantum ranges from 10 to 100 mille seconds 100 mille seconds
Example of RR with Time Quantum = 20Example of RR with Time Quantum = 20
ProcessProcess Burst TimeBurst TimePP11 5353 PP22 1717 PP33 6868 PP44 2424
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
0 20 37 57 77 97 117 121 134 154 162
Multi level QueueMulti level Queue Ready queue is partitioned into separate queues:Ready queue is partitioned into separate queues:
foreground (interactive)foreground (interactive)background (batch)background (batch)
Each queue has its own scheduling algorithmEach queue has its own scheduling algorithm– foreground – RRforeground – RR– background – FCFSbackground – FCFS
Scheduling must be done between the queuesScheduling must be done between the queues– Fixed priority scheduling; (i.e., serve all from Fixed priority scheduling; (i.e., serve all from
foreground then from background). Possibility of foreground then from background). Possibility of starvation.starvation.
– Time slice – each queue gets a certain amount Time slice – each queue gets a certain amount of CPU time of CPU time
Multi level Queue Multi level Queue SchedulingScheduling
Multi level Feedback QueueMulti level Feedback Queue
A process can move between the various queues A process can move between the various queues Multilevel-feedback-queue scheduler defined by the Multilevel-feedback-queue scheduler defined by the
following parameters:following parameters:– number of queuesnumber of queues– scheduling algorithms for each queuescheduling algorithms for each queue– method used to determine when to upgrade a method used to determine when to upgrade a
processprocess– method used to determine when to demote a method used to determine when to demote a
processprocess– method used to determine which queue a process method used to determine which queue a process
will enter when that process needs servicewill enter when that process needs service
Example of Mult i level Feedback QueueExample of Mult i level Feedback Queue
Three queues: Three queues: – QQ00 – RR with time quantum 8 milliseconds – RR with time quantum 8 milliseconds
– QQ11 – RR time quantum 16 milliseconds – RR time quantum 16 milliseconds
– QQ22 – FCFS – FCFS SchedulingScheduling
– A new job enters queue A new job enters queue QQ00 which is servedwhich is served FCFS. When it gains CPU, job receives 8 FCFS. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue milliseconds, job is moved to queue QQ11..
– At At QQ11 job is again served FCFS and receives 16 job is again served FCFS and receives 16 additional milliseconds. If it still does not additional milliseconds. If it still does not complete, it is preempted and moved to queue complete, it is preempted and moved to queue QQ22..
Multi level Feedback Multi level Feedback QueuesQueues
Multiple-Processor SchedulingMultiple-Processor Scheduling
CPU scheduling more complex when CPU scheduling more complex when multiple CPUs are availablemultiple CPUs are available
Homogeneous processorsHomogeneous processors within a within a multiprocessormultiprocessor
Load sharingLoad sharing Asymmetric multiprocessingAsymmetric multiprocessing – only one – only one
processor accesses the system data processor accesses the system data structures, alleviating need for data sharingstructures, alleviating need for data sharing
Real-Time SchedulingReal-Time Scheduling
Hard real-timeHard real-time systems – required to systems – required to complete a critical task within a complete a critical task within a guaranteed amount of timeguaranteed amount of time
Soft real-timeSoft real-time computing – requires that computing – requires that critical processes receive priority over critical processes receive priority over less fortunate onesless fortunate ones