CPU Process Scheduling

Operating Systems Part 5

ยท

5 min read

CPU Process Scheduling

CPU Process Scheduling Algorithms

Two types - Preemptive & Non-Preemptive

Pre-Emptive AlgorithmsNon Pre-Emptive Algorithms
1. SRTF(Shortest Remaining Time First)1. FCFS(First Come First Serve)
2. LRTF(Longest Remaining Time First)2. SJF(Shortest Job First)
3. Round Robin3. LJF(Longest Job First)
4. Priority based4. HRRN(Highest Response Ratio Next)
5. Multilevel Queue

Timings in CPU Scheduling

  1. Arrival Time - The time at which process enters the Ready queue or State.
  2. Burst Time - Time required by a process to get executed on CPU.
  3. Completion Time - The time at which process completes its execution.
  4. Turn Around Time = { Completion Time - Arrival Time }
  5. Waiting Time = { Turn Around Time - Burst Time }
  6. Response Time = { Time at which a process gets CPU first time - Arrival Time }

First Come First Serve(FCFS) CPU Scheduling Algorithm

  1. Criteria : Arrival Time.
  2. Mode : Non-Preemptive.
  3. Use Gantt Chart to solve numericals.
  4. Based on given Arrival and Burst Times of various processes, we find out their completion time, turnaround time, waiting time, response time using their formulas.
  5. Also, find the average completion time, average turnaround time and average waiting time.
  6. Response time will be equal to waiting time because FCFS is non-preemptive.

Shortest Job First(SJF) CPU Scheduling Algorithm

  1. Criteria : Processes with least Burst Time.
  2. Mode : Non - Preemptive.
  3. Similar to FCFS, based on given arrival and burst times, we find out their completion time, turnaround time, waiting time, and response time.
  4. Plot the Gantt Chart for processes being executed in CPU.
  5. Calculate the average timings.
  6. In non-preemptive algorithms, waiting time is always equal to response time.

Shortest Job First with Preemption(SJF + Preemption) CPU Scheduling Algorithm

  1. SJF with Preemption is also known as Shortest Remaining Time First(SRTF) Scheduling Algorithm.
  2. Criteria : Burst Time.
  3. Mode : Preemptive.
  4. More complicated numericals as you have to check the least burst time among all processes in the ready queue at every step.
  5. If two processes have equal burst time, then consider their arrival times. The process with lower arrival time gets executed first.
  6. Response time will be different than waiting time, because of preemption.

Round Robin(RR) CPU Scheduling Algorithm

  1. Criteria : Time Quantum
  2. Mode : Preemptive
  3. Use two Gantt charts for Ready Queue and Running Queue. Based on the given Time Quantum value, the arrival and burst times of processes, we calculate the CT, TAT, WT, RT.
  4. Context switching happens when a running process is preempted back into the Ready Queue from the Running Queue when it has run for the specified Time Quantum value. The context of the Process Control Block of the running process is saved and the process is sent back to the Ready Queue and a new process is brought in to be executed.

Pre-Emptive Priority CPU Scheduling Algorithm

  1. Criteria : Priority.
  2. Mode : Pre-Emptive.
  3. Wether Higher Number = Higher Priority OR Lower Number = Higher Priority. Will be given in the question.
  4. Based on the priority of processes, arrival and burst times, we calculate the CT, TAT, WT. Use Gantt chart for Running Queue.
  5. In case of equal priority of two processes, use their arrival time. The one with lower arrival time gets executed first.

Multilevel Queue Scheduling

  1. Processes can be of different types, and there are different Ready Queues for them.
  2. System Processes have highest priority and are scheduled using Round Robin algorithm.
  3. Interactive Processes like media players have medium priority scheduled using SJF algorithm and have a separate Ready queue.
  4. Batch Processes are background processes, have lowest priority scheduled using FCFS algorithm.
  5. Drawback is that the response times of batch processes will be very high, because the system processes will keep the CPU occupied leaving less time for interactive and batch processes to execute. This is the problem of starvation. This drawback is overcome by Multilevel Feedback Queue Scheduling.

Multilevel Feedback Queue Scheduling

  1. Lowest priority processes face the problem of starvation, which can be solved by feedback, where a low priority processes is progressively upgraded to a higher priority queue each time it is executed for a defined time quantum.
  2. Processes which are already high priority do not face the problem of starvation.
  3. The lowest priority process is executed for some time quantum, or it can be any algorithm for that matter. It is then given an upgrade to a queue having a higher priority and this process continues to the highest priority queue till the process has been executed completely.

Conclusion

You can read other articles written by me through these links.

Operating System Series
1. Introduction & Types of OS
2. Process States & Lifecycle
3. System Calls
4. User Mode vs Kernel Mode
5. CPU Process Scheduling
6. Process Synchronization
7. Deadlocks
8. Memory Management
9. Disk Management & Scheduling
10. File System in OS
11. Protection & Security

System Design Series
Introduction To Parallel Computing
Deep Dive Into Virtualization
Insights Into Distributed Computing

Cloud Computing Series
1. Cloud Service Models
2. Cloud Deployment Models
3. Cloud Security
4. Cloud Architecture
5. Cloud Storage
6. Networking In The Cloud
7. Cloud Cost Management
8. DevOps In Cloud & CI/CD
9. Serverless Computing
10. Container Orchestration
11. Cloud Migration
12. Cloud Monitoring & Management
13. Edge Computing In Cloud
14. Machine Learning In Cloud

Computer Networking Series
1. Computer Networking Fundamentals
2. OSI Model
3. TCP/IP Model : Application Layer
4. TCP/IP Model : Transport Layer
5. TCP/IP Model : Network Layer
6. TCP/IP Model : Data Link Layer

Version Control Series
1. Complete Guide to Git Commands
2. Create & Merge Pull Requests
3. Making Open Source Contributions

Linux
Complete Guide to Linux Commands

Thanks For Reading! ๐Ÿ’™
Garvit Singh

ย