Process scheduling in CPU refers to the technique used by operating systems to manage the execution of multiple processes on a single CPU. The operating system is responsible for allocating CPU time to each process in a fair and efficient manner, based on a predefined scheduling algorithm.
Types of CPU Scheduling –
There are two main types of CPU scheduling algorithms used by operating systems: preemptive and non-preemptive.
Pre-emptive CPU scheduling
Pre-emptive CPU scheduling is a technique used by operating systems to efficiently allocate the CPU to multiple processes or threads. In pre-emptive scheduling, the operating system interrupts the currently executing process or thread and switches to another process or thread based on a predefined scheduling algorithm.
The goal of pre-emptive scheduling is to ensure that all processes or threads have a fair share of CPU time, and that no process or thread monopolizes the CPU. This improves the overall system performance and responsiveness, as it allows multiple processes or threads to run concurrently without waiting for each other.
Non-Pre-emptive CPU scheduling
Non-preemptive CPU scheduling is another technique used by operating systems to allocate the CPU to multiple processes or threads. In non-preemptive scheduling, the currently executing process or thread continues to run until it completes its execution or blocks for some reason.
Unlike pre-emptive scheduling, the operating system does not interrupt the currently executing process or thread to switch to another one, unless the currently running process blocks or voluntarily gives up the CPU. As a result, non-preemptive scheduling algorithms may lead to longer waiting times for some processes or threads, and may not be as efficient as pre-emptive scheduling in certain situations.
One advantage of non-preemptive scheduling is that it is simpler and less resource-intensive than pre-emptive scheduling, as there is no need to constantly switch between processes or threads. This can be useful in certain real-time applications, where predictable execution times are more important than overall system performance.
Some common non-preemptive scheduling algorithms include First-Come-First-Serve (FCFS), Shortest Job First (SJF), and Priority-based scheduling. In these algorithms, the scheduler chooses the next process or thread to run based on its arrival time, execution time, or priority, respectively.
Criteria for CPU scheduling –
There are several processes kept in the main memory by the short-term scheduler. The selection of a process from the main memory and given to the CPU for execution is done on the basis of certain algorithms. These algorithms are known as CPU scheduling algorithms. There are various criteria according to which an algorithm is selected over another. The various scheduling criteria are –
- CPU Utilization – CPU needs to be kept busy all the time. It should not be idle. CPU utilization can range from 0 to 100 percent. CPU utilization from 40 to 90 percent is considered as good whereas below this is considered poor.
- Throughput – This is a measure of rate of work done in a system. It is defined as the number of processes per unit time.
- Turn Around Time – It is defined as the time interval between the submission of a process to the time of completion.
- Waiting Time – It is defined as the sum of time periods that are spent by the processes waiting in the queue.
- Response Time – Turnaround time is sometimes considered to be a bad criterion because there may exist situations where a process has completed a process quite fast and started computation of the next process, while results of the previous are being output to the user. Therefore, response time is considered to be a better criterion. The time from the submission of the process to the time it executes is called response time.
So, it is considered better to have a maximum CPU utilization and throughput and a minimum turnaround time, waiting time, and response time. In some cases, it is preferred to optimize the average value of these criteria whereas cases may arise where optimizing the minimum and maximum values may give better results.
So, in this article, we learned about the two different types of CPU scheduling and the criteria for CPU scheduling.
There are various algorithms for CPU scheduling which will be discussed in further articles.