What is the CPU Scheduler?
CPU scheduler will select a process from the ready process from the memory and will allocate the CPU to that process. CPU scheduling decisions occur when a process:-
CPU scheduler will select a process from the ready process from the memory and will allocate the CPU to that process. CPU scheduling decisions occur when a process:-
- Switches from "Running" to "Waiting" state.
- Switches from "Running" to "Ready" state.
- Switches from "Waiting" to "Ready".
- Terminates.
Types of Schedulers:-
There are 3 types of Scheduler.
Long Term Scheduler:-
Long Term Scheduler Or Job Scheduler selects a process from the storage device and loads them into memory for execution.
Short Term Scheduler:-
The Short term scheduler or CPU scheduler selects from among processes that are ready to execute and allocates the CPU to one of them.
Medium Term Scheduler:-
The Medium-Term Scheduler removes processes from memory and thus reduces the degree of multi-programming (The number of processes in memory). At some later time, the process can be reintroduced into the memory and its execution can be continued where it left off. this scheme is called as Swapping. The process is swapped out and is late swapped in by the medium-term scheduler.
Dispatcher:-
Dispatcher module gives control of the CPU to the process selected by the short term scheduler, this involves: Switching context 2. Switching to user mode 3. jumping to the proper location in the user program to restart the program.
Dispatch Latency:-
The time is taken by the dispatcher to stop one process and start another process.
Scheduling Queues:-
The scheduler uses various queues in the scheduling process:
Dispatcher:-
Dispatcher module gives control of the CPU to the process selected by the short term scheduler, this involves: Switching context 2. Switching to user mode 3. jumping to the proper location in the user program to restart the program.
Dispatch Latency:-
The time is taken by the dispatcher to stop one process and start another process.
Scheduling Queues:-
The scheduler uses various queues in the scheduling process:
Job queue:- all processes are once submitted in the job queue.
Ready queue:- The processes that are ready and waiting for execution are in the ready queue.
usually, a long term scheduler selects processes from the job queue to the ready queue.
short term scheduler selects a process from the ready queue for execution.
Device queue:-when a process is blocked in an I/O operation, It is usually put in a device queue(waiting for a device). when an I/O operation is completed, the process is moved from the device queue to the ready queue.
Performance Metrics of CPU scheduling:-
CPU Utilisation:- Percentage of time that CPU is busy.
Throughput:- The number of processes completed per unit time. For the long process, this rate may be 1 process per hour, for short transactions throughput might be 10 processes per second.
Turnaround Time:- The interval from the time of submission of a process to the time of completion. Turnaround time is the sum of the periods spent waiting to get into memory, waiting in the ready queue, executing on the CPU, and doing I/O.
Waiting Time:- The sum of the periods spent waiting in the ready queue.
Response Time:- The time of Submission to the time the first response is produced, but not the time that it takes to output that response.
Preemptive Vs Non Preemptive scheduling:-Many CPU scheduling algorithms have both preemptive and non-preemptive versions.
Preemptive:- Schedule a new process even when the current process doesn't intend to give up the CPU.
Non-Preemptive:- Only schedule a new process when the current one doesn't want CPU anymore.
When do we perform non-preemptive scheduling?
Preemptive Vs Non Preemptive scheduling:-Many CPU scheduling algorithms have both preemptive and non-preemptive versions.
Preemptive:- Schedule a new process even when the current process doesn't intend to give up the CPU.
Non-Preemptive:- Only schedule a new process when the current one doesn't want CPU anymore.
When do we perform non-preemptive scheduling?
- A process switches from the running state to "Waiting" state(I/O request)
- A process switches from the "Running" state to the "Ready" state.
- A process switches from "Waiting" state to "Ready" state(complete of an I/O operation).
- A process terminates.
Scheduling Algorithms:-
- FIFO
- Round Robin
- Priority Scheduling
- Shortest Job First
- Multilevel Feed Back Queue Scheduling
