presentation by adeel

18

Upload: goodthingbetter

Post on 07-Aug-2015

31 views

Category:

Education


2 download

TRANSCRIPT

Topic:- Scheduling Algorthuim

Presentation by M Adeel

Rajput

Insc:- Sir Sajjad

Content

• Basic concept• Scheduling Criteria• First Come, First Served (FCFS)• Shortest-Job-First (SJF) Scheduling• Priority Scheduling • Round Robin (RR) • Which CPU Scheduling Algorithms

Can be Preemptive?

Basic concept

• In computer science, scheduling is the method by which threads, processes or data flows are given access to system resources

• Long-term scheduling• Medium-term scheduling• Short-term scheduling

Scheduling Criteria

• CPU utilization • Throughput• Turnaround time • Waiting time • Response time

First Come, First Served (FCFS),• is the simplest scheduling algorithm, FIFO

simply queues processes in the order that they arrive in the ready queue.

• The FCFS scheduling algorithm is non preemptive. Once the CPU has been allocated to a process, that process keeps the CPU until it releases the CPU.

example

Process Burst TimeP1 24 P2 3 P3 3

• Suppose that the 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

P1 P2 P3

Shortest-Job-First (SJF) Scheduling

• Associate with each process the length of its next CPU burst. When the CPU is available, it is assigned to the process that has the smallest next CPU burst.

Two schemes:

– Non-preemptive – 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)

Example Non-preemptive

Process Arrival Time Burst TimeP1 0.0 7

P2 2.0 4

P3 4.0 1

P4 5.0 4• SJF (non-preemptive)

• Average waiting time = (0 + 6 + 3 + 7)/4 = 4

P1 P3 P2

73 160

P4

8 12

P1 P3 P2 P4

Example preemptive Process Arrival Time Burst TimeP1 0.0 7

P2 2.0 4

P3 4.0 1

P4 5.0 4• SJF (preemptive)

• Average waiting time = (9 + 1 + 0 +2)/4 = 3

P1 P3P2

42 110

P4

5 7

P2 P1

16

P1 P3P2 P4 P1P2

Priority Scheduling

• A priority number (integer) is associated with each process

• The CPU is allocated to the process with the highest priority (smallest integer highest priority)– Preemptive– non preemptive

• SJF is a priority scheduling where priority is the predicted next CPU burst time

• Problem Starvation – low priority processes may never execute

• Solution Aging – as time progresses increase the priority of the process

Example of Priority Scheduling Process Burst Time Arrival Time

Priority P1 10 0 3

P2 1 0 1

P3 2 0 4

P4 1 0 5

P5 5 0 2

P3P5P2

61 190 16 18

P3P5P2

61 190 16 18

P4P1P2 P5 P1 P3 P4

Round Robin (RR)

• 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.

Example of RR with Time Quantum = 4

Process Burst Time Arrival

P1 24 0 P2 3 0 P3 3 0

• The Gantt chart is:

• Average waiting time: (0+4+7+(10-4))/3 = 5.66

With FCFS: (0+24+27)/3 = 17

P1 P2 P3 P1 P1 P1 P1 P1

0 4 7 10 14 18 22 26 30

P2 P3 P1 P1P1 P1P1P1

Which CPU Scheduling Algorithms Can be Preemptive?

• FCFS (First-come, First-Served)– Non-preemptive

• SJF (Shortest Job First)– Can be either– Choice when a new (shorter) job arrives– Can preempt current job or not

• Priority– Can be either– Choice when a processes priority changes

or when a higher priority process arrives