cpu sheduling
TRANSCRIPT
Operating System Concepts Prasad Sawant
CPU Scheduling
Prof.Prasad Sawant Lecturer MCA
MACS College Pune
Operating System Concepts Prasad Sawant
Alternating Sequence of CPU And I/O Bursts
Operating System Concepts Prasad Sawant
CPU Scheduler
• Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them.
• CPU scheduling decisions may take place when a process:1.Switches from running to waiting state.2.Switches from running to ready state.3.Switches from waiting to ready.4.Terminates.
• Scheduling under 1 and 4 is nonpreemptive.• All other scheduling is preemptive.
Operating System Concepts Prasad Sawant
Dispatcher
• Dispatcher module gives control of the CPU to the process selected by the short-term scheduler.
Operating System Concepts Prasad Sawant
Scheduling Criteria
• CPU utilization – keep the CPU as busy as possible
• Throughput – # of processes that complete their execution per time unit
• Turnaround time – amount of time to execute a particular process
• Waiting time – amount of time a process has been waiting in the ready queue
Operating System Concepts Prasad Sawant
Keep in mind
• Waiting time (WT)=start time(ST)-Arrival time (AT)• Finish time (FT)=start time(ST)+Burst Time(BT)• Total turn around time(TOT)=Finish time(FT)-Arrival time (AT )
Operating System Concepts Prasad Sawant
Optimization Criteria
• Max CPU utilization• Max throughput• Min turnaround time • Min waiting time • Min response time
Operating System Concepts Prasad Sawant
First-Come, First-Served (FCFS) SchedulingSuppose that the processes arrive in the order: P1 , P2 , P3
0 10 20 30
P1 24
P2 27
P3 30 Waiting time for P1 = 0;
P2 = 24; P3 = 27Average waiting time: (0 + 24 + 27)/3 = 17
schedule
schedule
schedule
Process Bust Time
P1 24
P2 3
P3 3
Operating System Concepts Prasad Sawant
Process Bust TimeP1 24P2 3P3 3
First-Come, First-Served (FCFS) Scheduling Gantt Chart
Suppose that the processes arrive in the order: P1 , P2 , P3
Waiting time for P1 = 0; P2 = 24; P3 = 27Average waiting time: (0 + 24 + 27)/3 = 17
schedule
schedule
schedule
0 P1 24 P2 27 P3 30
Operating System Concepts Prasad Sawant
Exercise
• Find Average waiting time for • Suppose that the processes arrive in the
order: P2 , P3 , P1
Process Burst Time
P1 24
P2 3
P3 3
Operating System Concepts Prasad Sawant
Shortest-Job-First (SJR) Scheduling
• Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time.
• Two schemes: – nonpreemptive – once CPU given to the process it cannot be
preempted until completes its CPU burst.– preemptive – if a new process arrives with CPU burst length less
than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF).
• SJF is optimal – gives minimum average waiting time for a given set of processes.
Operating System Concepts Prasad Sawant
Example of Non-Preemptive SJFProcess A T Burst Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4
0 P1 7 P3 8 P2 12 P4 16
schedule
schedule
schedule
schedule
Average waiting time = (0+6+3+7)/4=4
Operating System Concepts Prasad Sawant
Example of Non-Preemptive SJFProcess AT BT ST WT(ST-AT) FT(ST+BT) TOT(FT-AT)
P1 0 7 0 0 7 7P2 2 4 8 6 12 10P3 4 1 7 3 8 4P4 5 4 12 7 16 11
P1 7 P3 8 P2 12 P4 16
Average waiting time = (0+6+3+7)/4=4
Average TOT =(7+10+4+11)/4=8
Operating System Concepts Prasad Sawant
Preemptive SJFProcess A.T. B.T S.T W.T
P1 0 8
P2 1 4
P3 2 9
P4 3 5
0 P1 1 P2 5
Pschedule
P4 10
schedule
7
P1 17
schedule
P3 26
schedule
10
1
17
5
10-1=9
1-1=0
17-2=15
5-3=2
Operating System Concepts Prasad Sawant
Priority SchedulingProcess BT Priority ST WT
P1 10 3
P2 1 1 High
P3 2 4
P4 1 5
P5 5 2
Avg waiting time
0 P2 1
0
P5 6 P1 16 P3 18 P4 19
Schedule
Schedule
Schedule
Schedule
Schedule
6
0
16
18
1
6
0
16
18
1
41/5=8.2 ms
Operating System Concepts Prasad Sawant
SJF Preemptive Priority Scheduling Process BT AT Priority ST WT
P1 8 0 4
P2 6 1 6
P3 7 3 3
P4 9 3 1(high)
Avg Waiting Time
0 P1 3
P 5
P4 12
scheduled
P3 19
scheduled
P1 24
scheduled
P2 30
scheduled
19
24
12
3
19-3=16
24-1=23
12-3=9
3-3=0
48/4=12 ms
Operating System Concepts Prasad Sawant
Round Robin Scheduling
• Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue.
• If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units.
Operating System Concepts Prasad Sawant
Time Quantum and Context Switch Time
Quantum Context Switch Process Time 10
12
6
1
0
1
9
0 10
6 10
2 3 4 5 6 7 8 9 101
Operating System Concepts Prasad Sawant
Round Robin Time Quantum 4Process Burst Time TOT
P1 24
P2 3P3 3
0 P1 4
24-4=20
P2 7
scheduled
P3 10
scheduled
P1 14
20-4=16
P1 18
16-4=12
P1 22
12-4=8
P1 26
8-4=4
P1 30
4-4=0scheduled 30
7
10
Operating System Concepts Prasad Sawant
Questions
1. Define the difference between pre-emptive and non-pre-emptive scheduling.
2. Explain the concept of a priority used in scheduling. Why is priority working usually chosen for real time processes?
3. Define by difference between preemptive and non-emptive scheduling.
4. Comment on the principle disadvantage of each of these scheduling methods: FCFS, SJF, RR
Operating System Concepts Prasad Sawant
Bibliography
• Operating System Principle-Peter Galvin Galvin
• Prof.S.G.Lakhdive (Dept .Computer Sci )Prof.Ramkirshna More A.C.S College Akurdi
• Mr. Abhishek Nagar Web Administrator at Symbiois
Operating System Concepts Prasad Sawant
Thanks you