CPU Scheduling – In case of single processor only one process can run at a time and other processes waits for until the processor free and can be rescheduled. The main objective of multiprogramming is to have some process running all the time to maximize the CPU utilization. In the single processor CPU sit idle whenever process request for the I/O completion all this waiting is wastage of time. To overcome this problem several processes are kept in memory at a time. Whenever one process has to wait the operating system assign another process to the CPU. This kind of scheduling is fundamental OS functions almost all the computer resources are schedule before use.
CPU and I/O Burst Cycle
The CPU’s scheduling success depends on an observed property of processes.
- The process execution includes a cycle of CPU execution and I/O wait process alternate b/w these two states.
- Execution of process is being with CPU burst which is followed by an I/O burst that is followed by CPU burst then other I/O burst and so on.
- Ultimately, the last CPU Burst ends with a system request to terminate execution.
- The main concern is the CPU burst distribution.
When the CPU turn out to be idle then the operating system must select one of the process in the ready queue to be executed. Short term scheduler is user for selection process. There are different kind of algorithms that are used for ready queue such as FIFO, LIFO priority queue and so on. Generally, PCB is used to keep the record of queues.
There are mainly two types of scheduling
- Preemptive scheduling
- Non-preemptive scheduling
There are main four circumstances in which CPU scheduling decision may take place:
- Whenever process switches from the running state to the wait state (as a result of I/O request or wait for termination of one of the child processes)
- Whenever a process switches form running state to ready state (i.e. when an interrupt occurs)
- Whenever a process switches form the waiting state to ready state (i.e. for I/O completion)
- When process terminates.
NOTE: for case 1 and 4 there is no choice in terms of scheduling, a new process must be selected for execution. In case 2,3 there is a choice.
- The scheduling which take places in case 1,4 then the scheduling is called as non-preemptive scheduling or cooperative.
- In case of non-preemptive scheduling once the CPU has been allocated to a process and the process preserves CPU until it releases the CPU either by terminating or by switching to the waiting state.
It is basically a module which offers control of the CPU to the process selected by short term scheduler. This function includes the following activities:
- Switching context
- Switching to the user mode
- In the user program jumping to the proper location to restart that program.
Dispatcher invoked during every process switch so it should be as fast as possible. The time taken by dispatcher to stop one process and start another process running is called as dispatcher latency.