The objective of CPU scheduling/process scheduling:
Increase the CPU utilization and increase processing speed.
Increase throughput.
Decrease Turn Around Time.
Decrease Response time and Waiting Time.
To provide a fair share of resources among the number of processes.
First Come First Serve (F C F S) Algorithm
Jobs are executed on a first-come, first-serve basis.
It is a non-preemptive scheduling algorithm.
Its implementation is based on the FIFO queue.
Poor performance as the average wait time is high
The implementation of the FCFS policy is easily managed with a FIFO queue. When a process enters a ready queue, the PCB is linked to the tail of the queue. when the CPU is free, it is allocated to the process at the head of the queue. In this algorithm, once the process has the CPU allocated, it runs to its completion which usually results in poor performance. As a consequence, there is a low rate of CPU utilization and system throughput.
short jobs may suffer considerable turnaround delays and waiting times when the CPU has been allocated to longer jobs.
Shortest Job first (SJF) Scheduling Algorithm:
There are two types of SJF Scheduling Algorithms: They are Non-Preemptive and Preemptive
Non-Preemptive – once CPU was given to the process it cannot be preempted until the process completes its CPU burst.
Preemptive – If a new process arrives with CPU burst length less than the remaining time of the current executing process then-current process gets preempted known as Shortest-Remaining-Time-First (SRTF)
Optimal for minimizing queueing time, but impossible to implement. Tries to predict the process to schedule based on the previous history.
Predicting the time the process will use on its next scheduled
scheduling of a job, a process is done on the basis of its shortest execution time. if the two processes have the same CPU time, then FCFS scheduling is used among them.
Shortest job first scheduling is an optimum scheduling algorithm in terms of minimizing the average waiting time of the given set of processes.
The shortest job first algorithm works optimally only when the exact future execution time of jobs is known at the time of scheduling.
Priority-Based Algorithm:
A priority is associated with each process, and the CPU is allocated to the process with the highest priority. if two or more two processes having Equal priority are scheduled in FCFS order.
A CPU algorithm that schedules processes based on priority.
It is used in Operating systems for performing batch processes.
In priority scheduling, a number is assigned to each process that indicates its priority level.
The lower the number, the higher the priority.
In this type of scheduling algorithm, if a newer process arrives, that is having a higher priority than the currently running process, then the currently running process is preempted.
Priorities can be defined either internally or externally.
Internally defined priorities use some measurable quantity. for example. Time limits, memory requirements, number of open files, etc.
External priorities are set by criteria that are external to the operating system, such as the importance of the process.
Priority scheduling can suffer from a major problem known as indefinite blocking, or starvation, in which a low-priority task can wait forever because there are always some other jobs around that have higher.
One common solution to this problem is aging, in which the priorities of jobs increase the longer they wait. Under this scheme, a low-priority job will eventually get its priority raised high enough that it gets run.
Round Robin Algorithm:
Round Robin scheduling is similar to FCFS scheduling, except that CPU bursts are assigned with limits called time quantum and it is preemptive in nature.
When a process is given the CPU, a timer is set for whatever value has been set for a time quantum.
If the process finishes its burst before the time quantum timer expires, then it is swapped out of the CPU just like the normal FCFS algorithm.
If the timer goes off first, then the process is swapped out of the CPU and moved to the back end of the ready queue.
The ready queue is maintained as a circular queue, so when all processes have had a turn, then the scheduler gives the first process another turn, and so on.
RR scheduling can give the effect of all processors sharing the CPU equally, although the average wait time can be longer than with other scheduling algorithms.
The performance of RR is sensitive to the time quantum selected. If the quantum is large enough, then RR reduces to the FCFS algorithm; If it is very small, then each process gets 1/nth of the processor time and shares the CPU equally.