Cpu Scheduling 6th Sem 2010 PPT
-
Upload
harshit-srivastava -
Category
Documents
-
view
1.842 -
download
1
description
Transcript of Cpu Scheduling 6th Sem 2010 PPT
Project Guide: Project Members:
Ms. Priyanka Paul Abhishek Bajpai
Devanshu GuptaHarshit SrivastavaKushagra Chawla
CPU Scheduling› Basis of multiprogramming operating systems
which organizes jobs so that CPU always has one to execute
› Refers to the way processes are assigned to run on the available CPUs
› By switching CPU among processes, OS can make computer more productive
Basic Concepts› Maximum CPU utilization obtained with
multiprogramming• Objective is to have some processes running at all
times• Every time one process has to wait, another process
takes over the use of CPU
› CPU–I/O Burst Cycle• Process execution consists of a cycle of CPU
execution and I/O wait
› CPU burst distribution
CPU-I/O Burst Cycle
Alternating sequence of CPU and I/O bursts
Histogram of CPU-burst Durations› Curve is exponential or hyper exponential, with
large number of short CPU bursts and small number of large CPU bursts
CPU Scheduler› Selects a process from the processes in the ready
queue or memory that are ready to execute and allocates the CPU to that process
› also known as; short-term scheduler
Preemptive Scheduling› CPU scheduling decisions may take place under
following circumstances:• When a process switches from running state to waiting
state• When a process switches from running state to ready state• When a process switches from waiting state to ready state• When a process terminates
› When scheduling take place only under conditions 1 & 4, the scheduling scheme is nonpreemptive; otherwise it is preemptive
› Preemptive scheduling provides the choice for selecting a new process for execution
Scheduling Criteria› CPU utilization : keep the CPU as busy as
possible
› Throughput: no. of processes completed per time unit
› Turnaround time : time taken to execute a process from submission to completion
› Waiting time : time that a process spends waiting in ready queue
› Response time : time from submission of a request until first
response is produced
Optimization Criteria› Max CPU utilization
› Max Throughput
› Min Turnaround time
› Min Waiting time
› Min Response time
Scheduling Algorithms› First-Come, First-Served Scheduling (FCFS)
› Shortest-Job-First Scheduling (SJF)
› Priority Scheduling
› Round-Robin Scheduling
First-Come, First-Served Scheduling› Runs jobs in the order they arrive
› Assume that processes arrive in the order: P1, P2, P3
› The Gantt Chart for the schedule is:
› Waiting time for P1= 0; P2= 24; P3 = 27
› Average waiting time: (0 + 24 + 27) / 3 = 17
P1 P2 P3
24 27 300
Process Burst Time
P1 24
P2 3
P3 3
› Assume that processes arrive in the order: P2, P3, P1
› The Gantt chart for the schedule is:
› Waiting time for P1 = 6; P2 = 0; P3 = 3
› Average waiting time: (6 + 0 + 3) / 3 = 3
› Much better than previous case
P1P3P2
63 300
Shortest-Job-First Scheduling› Associates with each process the length of its
next CPU burst
› Process having smallest next CPU burst is assigned to the available CPU
› Two schemes: • Nonpreemptive- once CPU is given to the process, it
can’t 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 then preempt
› SJF is optimal• gives minimum average waiting time
Example of Nonpreemptive SJF
› The Gantt Chart for the schedule is:
› Average waiting time = (0 + 6 + 3 + 7) / 4 = 4
Process Arrival Time Burst Time
P1 0 7
P2 2 4
P3 4 1
P4 5 4
P1 P3 P2
73 160
P4
8 12
Example of Preemptive SJF (SRTF)
› The Gantt Chart for the schedule is:
› Average waiting time = (9 + 1 + 0 +2) / 4 = 3
Process Arrival Time Burst Time
P1 0 7
P2 2 4
P3 4 1
P4 5 4
P1 P3P2
42 110
P4
5 7
P2 P1
16
Priority Scheduling› A priority is associated with each process
› CPU is allocated to the process having highest priority
› Equal priority processes are scheduled in FCFS order
› SJF algorithm is a priority algorithm where priority is the inverse of the next CPU burst
› Problem• Starvation - low priority processes may never execute
› Solution• Aging - as time progresses, increase the priority of the
process
Example of Priority Scheduling
› The Gantt Chart for the schedule is:
› Average waiting time = (6 + 0 + 16 + 18 + 1) / 5 = 8.2
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
P2
P5 P1 P3 P40 6 16 19181
Round-Robin Scheduling› Designed for time sharing systems
› Similar to FCFS scheduling with added preemption
› A small unit of time called time quantum/time slice is defined (10-100 ms)
› After time quantum has elapsed, the process is preempted and added to the tail of the ready queue
› New processes are added to the tail of the ready queue
Example of Round-Robin Scheduling
› Time Quantum = 20 › The Gantt Chart for the schedule is:
› Higher avg. turnaround time than SJF, but better response
Process Burst Time
P1 53
P2 17
P3 68
P4 24
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
0 20 37 57 77 97 117 121 134 154 162
Design Constraints
› Implemented in JAVA Language
› Operating System : Windows XP
› No Database Connectivity
SDLC Model› Iterative waterfall model
Level 0 DFD
Level 1 DFD
Coding Progress
› FCFS.java
› Round-Robin.java
Any Queries ?