CPU Scheduling Algorithms in Operating System
Why an OS has to schedule processes
Processes or jobs competing for CPU are not of the same type or have the same level of importance. For example some processes are CPU bound while other processes are IO bound. In the later case when a process blocks for IO the OS should let other processes use the CPU otherwise the computation resource is not going to be utilized as expected. Here is an overall list of scheduling goals sorted by system type:
All systems
- Fairness: give each process a fair share of the CPU
- Enforcement: ensure that the stated policy is carried out
- Balance: keep all parts of the system busy
Batch Systems
- Throughput: maximize jobs per unit time
- Turnaround: minimize the time users wait for jobs
- CPU utilization: keep the CPU as busy as possible
Interactive Systems
- Response time: respond quickly to user requests
- Proportionality: meet user expectations
Real-time Systems
- Meet deadlines: missing deadlines is a system failure
- Predictability: same type of behavior for each time slice
So we now know why scheduling is important. Let us explore some of the well known scheduling algorithms:
First Come First Serve (FCFS)
- Serve the jobs in the order they arrive
- Non-Premptive scheduling algorithm
- Simple and easy to implement
- Longer jobs delay shorter jobs
Shortest Job First (SJF)
- Short jobs complete first
- Long jobs may starve
- Rarely used because time is hard to estimate
Shortest Remaining Time First (SRTF)
- This is the preemptive form of SJF
- Reevaluate when a new job is submitted
- Rarely used because time is hard to estimate
Three Level Scheduling
- Scheduling jobs for admission to memory
- Scheduling jobs to use the CPU
- Memory scheduler to move jobs back to disk
Round Robin Scheduling
- Give each ready process a time slot called quantum
- Too short quantum hearts efficiency
- Too long quantum hearts responsiveness
Priority Scheduling
- Assign a priority to each running process
- Decrease priority as process runs
- Increase priority when a process waits for IO
- Group processes with the same priority then use round robin
Shortest Process Next Scheduling
- Serve the process that will finish the soonest
- Guess completion time based on previous runs
Lottery Scheduling
- Give processes tickets for CPU time
- More tickets a process gets more CPU time it gets
- Tickets can be transferred between cooperating processes
Multi-Level Feedback Queue Scheduling
- A process can move between queues and have a different priority with each queue
- If a process uses too much CPU time it will be moved to a lower priority queue
- If a process waits too long in the lower priority queue it may be moved to a higher priority queue
- Aging prevents starvation
CPU scheduling algorithms in os PDF
You can find this article in PDF format here
About Author
Mohammed Abualrob
Software Engineer @ Cisco