Computer Fundamental
Computer Tutorial

CPU Scheduling



CPU Scheduling

• CPU or processor is one of the primary computer resources. All computer resources like I/O, memory, and CPU are scheduled for use.
• CPU scheduling is important for the operating system. In a multiprogramming and time sharing system, the processor executes multiple processes by switching the CPU among the processes, so that no user has to wait for long for a program to execute. To enable running of several concurrent processes, the processor time has to be distributed amongst all the processes efficiently.
• Scheduler is a component of the operating system that is responsible for scheduling transition of processes. At any one time, only one process can be in running state and the rest are in ready or waiting state. The scheduler assigns the processor to different processes in a manner so that no one process is kept waiting for long.
• Scheduling can be non-pre-emptive scheduling or pre-emptive scheduling. In non-preemptive scheduling, the processor executes a process till termination without any interruption. Hence the system resources are not used efficiently. In pre-emptive scheduling, a running process may be interrupted by another process that needs to execute. Pre-emption allows the operating system to interrupt the executing task and handle any important task that requires immediate action. In pre-emptive scheduling, the system resources are used efficiently.
• There are many different CPU scheduling algorithms that are used to schedule the processes. Some of the common CPU scheduling algorithms are as follows—

First Come First Served (FCFS) Scheduling

As the name says, the process that requests for the CPU first, gets the CPU first. A queue is maintained for the processes requesting the CPU. The process first in the queue is allocated the CPU first. FCFS scheduling is non-pre-emptive. The drawback of this scheduling algorithm is that the process that is assigned to the CPU may take long time to complete, keeping all other processes waiting in the queue, even if they require less CPU time.

Shortest Job First (SJF) Scheduling

The process that requires the least CPU time is allocated the CPU first. SJF scheduling is non-pre-emptive. The drawback of this scheduling is that a process that requires more CPU time may have to wait for long time, since processes requiring less CPU time will be assigned the CPU first.

Round Robin (RR) Scheduling

It is designed for time-sharing systems. RR scheduling is pre-emptive. In this scheduling, a small quantum of time (10—100 ms) is defined, and each process in the queue is assigned the CPU for this quantum of time circularly. New processes are added at the tail of the queue and the process that has finished execution is removed from the queue. RR scheduling overcomes the disadvantage of FCFS and SJF scheduling. A process does not have to wait for long, if it is not the first one in the queue, or, if it requires CPU for a long period of time.