CPU scheduling is the basis of multiprogramming operating systems. By switching the CPU between multiple processes the operating system can make the computer more productive.
In a single core CPU only one process can execute at a time so one process has to wait for another process for comletition to continue for its own execution. This way to executing processes can be very unproductive because one process can halt whenever it needs some input or some I/O interrupt.
A Scheduling algorithm is used in Operating Systems that allows the OS to schedule the processes in such a way that the process that needs some input from some I/O device is halted and some other process is give the CPU and other resources for its execution.
The objective of multiprogramming is to have some process running always to maximize CPU utilization. Several processes are kept in CPU at a time and the scheduler swithces between these processes to execute them more efficiently. Everytime one process has to wait for some I/O device another process takes its place in CPU.
Scheduling of this kind is a fundamental operating-system function. CPU is the primary resource a computer has thus all the processes are scheduled before execution to better use the CPU.
CPU-I/O Burst Cycle
Process execution is a cycle of CPU execution and I/O wait and all processes alterante between those two states.
A process execution begins with a CPU Burst. It then follows an I/O wait which is followed by anohter CPU burst and so on and on until a CPU burst ends with a system call to terminate the process.
CPU Scheduler
A process when enters a wait state and the CPU sits idle, the OS must select some process from the ready queue to utilize the idle CPU. To do this selection CPU Schedulers are used. They select the process from ready queue and allocate the CPU to them to handle their execution.
A Scheduler uses scheduling algorithms to do this selection. I have written about the scheduling algorithms in the post in Day 63 and Day 64.