Sie sind auf Seite 1von 7

STA.

ANA, RONA MAE IT 3Y2-1

1. First Come First Served Algorithm

Reference: http://www.sciencehq.com/computing-technology/first-come-first-
served-algorithm.html

First come first served scheduling algorithm (FCFS)

FCFS also termed as First-In-First-Out i.e. allocate the CPU in order in which the process
arrive. When the CPU is free, it is allowed to process, which is occupying the front of the
queue. Once this process goes into running state, its PCB is removed from the queue. This
algorithm is non-preemptive.

Advantage

 Suitable for batch system.

 It is simple to understand and code.

Disadvantage

 Waiting time can be large if short request wait behind the long process.

 It is not suitable for time sharing system where it is important that each user should
get the CPU for equal amount of time interval.

Examples
Consider the following set of processes having their CPU-burst time. CPU burst time
indicates that for how much time, the process needs the CPU.

process Time for which cpu is required


CPU burst time
p1 10
p2 5
p3 5

If the processes have arrived in order P1, P2, P3 then the average waiting time for process
will be obtained from Gantt chart.
STA. ANA, RONA MAE IT 3Y2-1

first come first out

Waiting Time for P1 = 0 Millisecond


Waiting Time for P2 = 10 Millisecond
Waiting Time for P2 = 15 Millisecond
Average Waiting Time = (0+10+15)/2 = 8.33 Millisecond

If the process arrive in order P2, P3, P1 then

Average Waiting Time = (0+5+10) / 3 = 5 Millisecond


Thus average waiting time will always depends upon the order in which the processes
arrive. And vary depending upon whether the processes having less CPU-burst arrive first in
the ready queue. Therefore this algorithm is never recommended whenever performance is
major issue.

2. Shortest job first scheduling

Reference: http://www.sciencehq.com/computing-technology/shortest-job-first-
scheduling.html

Shortest job first scheduling


Key concept of this algorithm is: “CPU is allocated to the process with least CPU-burst time.”
Amongst the processes in the ready queue. CPU is always assigned to the process with least
CPU burst requirement. If the two processes having the same length, next CPU burst, fcfs
scheduling is used i.e. one which arrives first, will be taken up first by the CPU.

This algorithm can be preemptive or non-preemptive.

Let us consider, the following set of processes having their CPU burst time mentioned in
millisecond and having arrived almost at the same time.

process CPU Burst Time

p1 10
STA. ANA, RONA MAE IT 3Y2-1

p2 5

p3 2

The Gantt chart:

Waiting time for P3 = 0 millisecond


Waiting time for P2= 2 millisecond
Waiting time for P1 = 7 millisecond
Average waiting time= (0+2+7) /3 = 3 millisecond

3. Shortest Remaining Time Scheduling

Reference: http://www.sciencehq.com/computing-technology/shortest-
remaining-time-scheduling.html

Shortest remaining time (SRT) scheduling


Shortest remaining time scheduling is the preemptive counter part of SJF and is useful in
time sharing system. In SRT, process with the smallest estimated run time to completion is
run next, in SJF once a job begin executing, it runs to completion. In SRT a running process
may be preempted by a user process with a shorter estimated run time.
Consider an example, where three processes arrived in the order P1, P2, P3 at the time
mentioned below, and then the average waiting time using SJF scheduling algorithm will be
calculated as:

process CPU Burst Time Time of Arrival

p1 10 0

p2 5 1

p3 2 2
STA. ANA, RONA MAE IT 3Y2-1

shortest remaining time scheduling

In this, the CPU will be taken away from the currently executing process whenever a
process will less CPU burst time.
As shown in figure, the time when P2 arrives P1 needs 9 millisecond more to finish. As B’s
cpu burst in 5 millisecond < 9 millisecond, therefore, P1’s execution will be preempted and
P2 will be executed but against as P3 arrives P2’s execution needs 3 more millisecond where
as P3 needs only 2 millisecond to execute, thus P3 takes over P2 and so on.

Waiting time for P1 = 0+ (8-1) = 7 millisecond


Waiting time for P2 = 1+ (4-2) = 3 millisecond
Waiting time for P3 = 2 millisecond
Average waiting time = (7+3+2) / 3 = 4 millisecond

4. Round robin scheduling

Reference: http://www.sciencehq.com/computing-technology/round-robin-
scheduling.html

Round Robin Scheduling


The basic purpose of this algorithm is to support time sharing system. This algorithm is
similar to the FCFS algorithm but now it is preempted FCFS scheduling. The preempted take
place after a fixed interval of time called quantum time of time slice. Its implementation
requires timer interrupt based on which the preemption take place.
Consider the set of the processes lined up in the ready queue. The processes are taken out
of the ready queue in FCFS order. Let us suppose that a process has been taken up for
execution now. The execution cannot go beyond that time slice. This process may either
finish up its execution before the time goes off or CPU will be preempted from it after the
timer goes off and this cause an interrupt to the operating system. At this time, context
switching will take place. The next process will be taken up from the ready queue. The
process, which is left by the CPU, will be added to the tail of the ready queue.
STA. ANA, RONA MAE IT 3Y2-1

robin hood scheduling

process CPU Burst Time


p1 10
p2 5
p3 2

The Gantt chart is shown below:

robin hood scheduling

Waiting time for P1 = 0 + (6-2) + (10-8) + (13-12) = 7 Millisecond


Waiting time for P2 = 2+ (8-4) + (12-10) = 8 millisecond
Waiting time for P3 = 4millisecond
Therefore average waiting time = (7+8+4)/3 = 6.33 Millisecond

As shown in figure: first p1 gets the cpu and get executed for 2 millisecond, then context
switching occurs and P2 get cpu for 2 millisecond, then again content switching occur and
P3 get cpu for 2 millisecond, since its cpu burst time is 2 millisecond only, therefore it
complete its execution and thus do not get the cpu again. P1 and P2 similarly continue to
share the CPU in the same fashion till they are done.

Overall performance depends on

 Size of the time quantum

 If time quantum is large than the CPU burst then this algorithm become same as
FCFS and thus performance degrade.
STA. ANA, RONA MAE IT 3Y2-1

 If the time quantum size is very small, then the number of content switches
increases and the time quantum almost equal the time taken to switch the CPU from
one process to another. Therefore 50% of time spent in switching of processes.

 Number of context switching

The number of context switches should not be too many to slow down the overall execution
of all the processes. Time quantum should be large with respect to the context switch time.

5. Priority Scheduling

Reference: http://www.sciencehq.com/computing-technology/priority-
scheduling.html

Priority scheduling
Each process in the system if given a priority, then the scheduling must be done according
to the priority of each process. A higher priority job should get CPU whereas lower priority
job can be made to wait. Priority scheduling is necessarily a form of preemptive scheduling
where priority is the basic of preemption.
Example:
Let us consider a set of processes P1, P2, P3 having priorities ranging from 1 to 3. Let us
assume that 1 is the highest priority whereas 3 is the least priority. Let us also assume that
p1 arrive first and P3 arrives in the last.

process CPU Burst Time Priority Arrival

p1 10 3 0

p2 5 2 1

p3 2 1 2

The Gantt chart is shown below:

Waiting time foe P1= o+ (8-1) =7

Waiting time for P2= 1+ (4-2) =3


STA. ANA, RONA MAE IT 3Y2-1

Waiting time for P3 = 2

Average Waiting Time = (7+3+2) / 3 = 4 Millisecond

Here, the preemption is based on the priority when P1 execute, P2 arrive with priority 2,
which is higher than priority 3 of P1, and thus P1 is preempted. Similarly when P2 execute,
P3 arrive with Priority 1 which is the highest priority and thus P2 is preempted and soon.

The main question arise here is if two processes have been assigned same priorities. Priority
may be assigned by user or by the operating system depending upon the important of
process. In that case comparison will be done with their CPU burst time. The process with
short CPU burst time will be executed first.

Das könnte Ihnen auch gefallen