Last day I learned about some simple algorihtms that are used in the OS design and today I will be learning about more algorithms that are also used in Operating Systems. These are scheduling algorithms that are mostly used in the Operating System's Scheduler for scheduling tasks.
Process Scheduler
A Process Scheduler is a part of the operating system that makes the decision for the CPU on what porcess to select form the queue to perform actions on it. The processes are placed in a queue and are selected by the scheduler to take actions on them by the CPU. There are three types of schedulers that work in an operating system but I will not be going in depth about them because this is about algorithms only and these are:
- Long Term Scheduler
- Short Term Scheduler
- Medium Term Scheduler
Scheduling Algorithms
A scheduler uses algorithms to decide the prioirty of the processes in the queue to feed them to the CPU and these algorithms are called Scheduler algorithms. There are atleast six very commin kinds of scheduler algorithms and I will be doning two of them today and maybe three or four of them tomorrow.
- FCFS Scheduling
- SJF Scheduling
- Priority Scheduling
- Round Robin Scheduling
- MLQ Scheduling
- Multiple Processor Scheduling
First Come First Serve (FCFS) Scheduling
A scheduling algorithm which is based on First Come First Serve basis. It means the process that enters the queue first will be executed first and so on. It is easy to implement and understand and kind of works the same way as the Data Structure Queue.
The disadvantages of this algorithm is that it is very much slow than most of the algorithms in the list. and takes a lot of time to process.
----- Before Execution -----
----- Processes -----
|1|2|3|4|5|6|7|8|9|
processBeingExecuted = 0
nextProcess = 1
----- After Execution -----
----- Processes -----
|2|3|4|5|6|7|8|9|
processBeingExecuted = 1
nextProcess = 2
Shortest Job First (SJF) Scheduling
Shortest Job First Scheduling algorithm pick the process first that will take the least amount of time to complete. By this way average waiting time is reduced by running the shortest job first. And easy to implement in systems where CPU time id known in advance and impossible to implement in systems where the process time is unknow at first. That is why to make is work fast, process time should be know at the beginnig of the process.
| Job | Arrival Time | Process Time |
| 0 | 1 | 5 |
| 1 | 0 | 2 |
| 2 | 2 | 1 |
processQueue = [2, 1, 0] // Based on Process Time