Scheduling (Algorithms) Policies (Priority)
Scheduling (Algorithms)
Policies (Priority):
These are the following different types of common policies or algorithms:
1)
First
Come First Served (FCFS) scheduling:
This is non-preemptive technique. A single queue of ready processes is
maintained, and the dispatcher always picks the first one. This method does not
emphasize throughput, since long processes are allowed to monopolize CPU, For
the same reason, the response time with FCFS can be high (with respect to
execution time), especially if there is a high variance in process execution
times. This is also known FCFS scheduling.
Consider the following example of two processes-
In the several processes come on different
job p1, p2 and p3 respectively, here p2 and p3 jobs required less than or
comparatively p1 process (job), but computer run p1 process in the process of
FCFS scheduler. P2 and p3 process has in ready queue in waiting process state.
Advantages: These are the following advantages of FCFS-
·
It is Simple policy.
·
It is easy to understand
·
It follows the First come
first served method.
Disadvantages:
These are the following disadvantages
of FCFS-
·
This scheduling method is
non-preemptive, the process will run until it finishes.
·
Because of this
non-preemptive scheduling, short processes which are at the back of the queue
have to wait for the long process at the front to finish.
Shortest job first (SJF) scheduling: It is known as the shorted job first. In this policy shortest job is selected in READY state and execute it. Here job or process is done on the basis of it having shortest execution time. If two processes have the same CPU time then FCFS is followed. As an example, consider the following set of processes.
Using shortest job scheduling this process would be scheduled in the P4-P1-P3-P2 waiting time is 0+3+8+16/4=6.75 units of time.
If we were using
the FCFS scheduling policy then the average waiting time will be
-0+3+15+23/4=10.75 units of time. Shortest job first may implement in either
non-preemptive or preemptive variety.
Round robin scheduling: Round robin schedule is oldest method. It is simplest widely used scheduling
policy. This policy is first used in a time sharing and multi-user system. In
the round robin scheme, a process is selected for running from the READY queue
in FIFO sequence. In round robin scheme the CPU time is divided into time slices.
Each process is allocated a small time slice (from 1 to 100 milliseconds) while
it is running. No process can run for more than one time slice when there are
others waiting in the READY queue. If a process needs more CPU time to complete
after using one time slice, it goes to the end of READY queue to wait the next
allocation. Round robin scheduling utilizes the system resources in any
equitable manner.
For example:
There are three processes P1, P2 and P3 with required the following CPU time.
If we use a time slice of 5 units of time, then P1 gets the first 5
units, of time. Since it requires another 20 units of time, it is preempted
after the first time slice and CPU is given to the next process that is P2.
Since P2 just needs 5 units of time it terminates as time slice expires. The
CPU is then given to the next process P3. Once each process is receive one time
slice, the CPU running to P1 for an additional time slice.
1.
Shortest
Remaining Time: It is the preemptive counterpart of
SJF and useful in time-sharing environment. In SRT scheduling, the process with
the smallest estimate run-time to completion is run next, including new
arrivals. In SJF scheme, once a job begins executing, it runs to completion.
In SJF scheme, a running process may
be preempted by a new arrival process with shortest estimated run-time. The
algorithm SRT has higher overhead than its counterpart SJF. The SRT must keep
track of the elapsed time of the running process and must handle occasional
preemptions. In this scheme, arrival of small processes will run almost
immediately. However, longer jobs have even longer mean waiting time.
2.
Priority
Scheduler: The basic idea is straightforward each
process is assigned a priority, and priority is allowed to run. Equal-Priority
processes are scheduled in FCFS order. The shortest-Job-First (SJF) algorithm
is a special case of general priority scheduling algorithm. An SJF algorithm is
simply a priority algorithm where the priority is the inverse of the
(predicted) next CPU burst. That is, the longer the CPU burst, the lower the
priority and vice versa. Priority can be defined either internally or
externally. Internally defined priorities use some measurable quantities or
qualities to compute priority of a process.
Examples of
Internal priorities are-
·
Time limits.
·
Memory requirements.
·
File requirements, for
example, number of open files.
·
CPU Vs I/O requirements.
Externally defined priorities are set by criteria that
are external to operating system such as-
·
The importance of
process.
·
Type or amount of funds
being paid for computer use.
·
The department sponsoring
the work.
·
Politics.
·
Priority scheduling can
be either preemptive or non-preemptive
·
A preemptive priority
algorithm will preemptive the CPU if the priority of the newly arrival process
is higher than the priority of the currently running process.
·
A non-preemptive priority
algorithm will simply put the new process at the head of the ready queue.
A major problem with priority
scheduling is indefinite blocking or starvation. A solution to the problem of
indefinite blockage of the low-priority process is aging. Aging is a technique
of gradually increasing the priority of processes that wait in the system for a
long period of time.
3. Multilevel queue
scheduling: A multilevel queue scheduling
algorithm partitions the ready queue in several separate queues, for instance
In
a multilevel queue scheduling processes are permanently assigned to one queue. The
processes are permanently assigned to one another, based on some property of
the process, such as
·
Memory size
·
Process priority
·
Process type
Algorithms choose the process from the occupied queue that has the
highest priority, and run that process either preemptive or non-preemptively.
Each queue has its own scheduling algorithm or policy.
Possibility I: If each queue has absolute priority over lower-priority queues then
no process in the queue could run unless the queues for the highest-priority
processes were all empty.
For example: In the above
figure no process in the batch queue could run unless the queues for system
processes, interactive processes, and interactive editing processes will all
empty.
Possibility II: If there is a time slice between the queues then each queue gets a
certain amount of CPU times, which it can then schedule among the processes in
its queue. For instance;
·
80% of the CPU time to
foreground queue using RR.
·
20% of the CPU time to
background queues using FCFS.
Since processes
do not move between queues so, this policy has the advantage of low scheduling
overhead, but it is inflexible.
4.
Multi-level
Feedback scheduling: Multilevel feedback
queue-scheduling algorithm allows a process to move between queues. It uses
many ready queues and associates a different priority with each queue. The
Algorithm chooses to process with highest priority from the occupied queue and
run that process either preemptively or un-preemptively. If the process uses
too much CPU time it will move to a lower-priority queue. Similarly, a process
that wait too long in the lower-priority queue may be moved to a
higher-priority queue.
Figure: Multilevel
Feedback Queue Scheduling
Example:
·
A process entering the ready queue is
placed in queue 0.
·
If it does not finish within 8
milliseconds time, it is moved to the tail of queue 1.
·
If it does not complete, it is preempted
and placed into queue 2.
·
Processes in queue 2 run on a FCFS basis,
only when 2 run on a FCFS basis queue, only when queue 0 and queue 1 are empty.
Comments
Post a Comment
Thank you for message