Process Scheduling in Operating System

Process Scheduling in Operating System

In Operating Systems, process scheduling plays an important role in managing resources efficiently. It's the mechanism through which the operating system decides which process to execute when. It helps in ensuring optimal utilization of CPU time and other system resources. Understanding process scheduling is crucial for developers, system administrators, and anyone interested in the intricacies of operating systems.


What is CPU Scheduling?

Process scheduling involves the selection of processes from the ready queue and allocating CPU time to them. A process scheduler schedules different processes to be assigned to the CPU.  Every modern operating system employs a scheduler to manage multiple processes concurrently. The primary goal is to optimize system performance, throughput, and response time while ensuring fairness and preventing starvation or resource contention.


Why use Scheduling Algorithm?

1. To maximize CPU utilization.
2. To provide fare allocation of CPU.
3. To maximize throughput (number of process completed per unit time.)
4. To minimize turn around time.
5. To minimize waiting time.
6. To minimize response time.

Preemptive Scheduling Algorithm

In preemptive scheduling. a running process can be interrupted and moved out of the CPU by the O.S even if it hasn't completed its full cpu burst. eg, SRTF (Shortest Remaining Time First), Round Robin, and Priority scheduling with preemption. 


Non-preemptive Scheduling Algorithm 

It does not allow the scheduler to interrupt a running process. Once a process is given to the CPU, it keeps it until it completes its entire CPU burst. Processes are selected for execution and run until they finish or block only after that does the scheduler select and dispatch another process. eg. FCFS (first come first serve), SJF (shortest job first) and Priority scheduling without preemption.


FCFS (Frist Come First Serve) Scheduling

The process which arrives first in the ready queue is firstly assigned the CPU. In case of tie, process with amaller process id is executed first. It is always non-preemptive in nature.

It can be easily implemented using queue data structure. It does not lead to starvation.
It does not consider the priority or burst time of the processes.

What is Starvation?

Due to priority some processes are on holding or waiting stage, it is known as starvation.


Arrival time: The time at which process entered in ready queue.

Execution or Burst time: Amount of time taken by process to execute.

Waiting Time: Turn Around Time - Burst Time (Difference between TAT and Burst Time.)

Turn Around Time: Completion Time - Arrival Time (Difference between Completion Time and Arrival Time.)

Completion Time: It is the time when process completes its execution.

Response Time: The time when process first get the CPU.

SJF (Shortest Job First) Scheduling

Out of all the available processes, CPU is assigned to the proces having smallest burst time. It can't be implemented practically since burst time of the processes cannot be known in advance. It leads to starvation for processes with larger burst time. Prioritses can't be set for the processes. Processes with larger burst time have poor response time.
Previous
Next Post »