Schedulers
Schedulers
The Operating system manages various types of queues for each of the
process states.
The PCB related to the process is also stored in the queue of the same
state. If the Process is moved from one state to another state then its
PCB is also unlinked from the corresponding queue and added to the
other state queue in which the transition is made.
Contd…
Job Queue: In starting, all the processes get stored in the job queue. It
is maintained in the secondary memory. The long term scheduler (Job
scheduler) picks some of the jobs and put them in the primary
memory.
Ready Queue: Ready queue is maintained in primary memory. The
short term scheduler picks the job from the ready queue and dispatch
to the CPU for the execution. A ready queue can be implemented as a
FIFO queue, a priority queue, a tree, or simply an unordered linked list.
Waiting (or Device) Queue: When the process needs some IO
operation in order to complete its execution, OS changes the state of
the process from running to waiting. The context (PCB) associated with
the process gets stored on the waiting queue which will be used by the
Processor when the process finishes the IO.
Process Scheduler
Schedulers in OS are special system software. They help in scheduling
the processes in various ways. They are mainly responsible for
selecting the jobs to be submitted into the system and deciding which
process to run.
Process State Transition Diagram
STS
LTS
MTS
Long Term Scheduler
Long term scheduler is also known as job scheduler. It chooses the
processes from the pool (secondary memory) and keeps them in the
ready queue maintained in the primary memory.
The primary objective of long-term scheduler is to maintain a good
degree of multiprogramming, i.e., number of process present in ready
state at any point of time.
The purpose of long term scheduler is to choose a perfect mix of I/O
bound and CPU bound processes among the jobs present in the pool.
Short term Scheduler
Short term scheduler is also known as CPU scheduler. It selects one of
the Jobs from the ready queue and dispatch to the CPU for the
execution.
TAT=WT+BT
TAT=CT-AT
WT=TAT-BT
Process or CPU Scheduling
In the uniprogrammming systems like MS DOS, when a process waits
for any I/O operation to be done, the CPU remains idol. In
Multiprogramming systems, the CPU doesn't remain idle during the
waiting time of the Process and it starts executing other processes.
The Operating system uses various scheduling algorithm to schedule
the processes on the CPU to have the maximum utilization of it and this
procedure is called CPU scheduling.
Different CPU-scheduling algorithms such as FCFS, round robin, SJF
have different properties, and the choice of a particular algorithm may
favor one class of processes over another. Many criteria have been
suggested for comparing CPU-scheduling algorithms.
Scheduling Criteria
CPU utilization:- The main objective of any CPU scheduling algorithm is
to keep the CPU as busy as possible. Theoretically, CPU utilization can
range from 0 to 100 but in a real-time system, it varies from 40 to 90
percent depending on the load upon the system.
Throughput:-A measure of the work done by CPU is the number of
processes being executed and completed per unit time. This is called
throughput. The throughput may vary depending upon the length or
duration of processes.
Turn Around Time:-The time elapsed from the time of submission of a
process to the time of completion is known as the turnaround time.
Turn-around time is the sum of times spent waiting to get into memory,
waiting in ready queue, executing in CPU, and waiting for I/O.
Contd…
Waiting time:- A scheduling algorithm does not affect the time
required to complete the process once it starts execution. It only affects
the waiting time of a process i.e. time spent by a process waiting in the
ready queue.
Response time:- The time from the submission of a request until the
first response is produced is called response time. It is the time it takes
to start responding, not the time it takes to output the response.
Gantt Chart
P1 P2 P3 P4 P5
0 2 8 12 21 33
Gantt Chart
P1 P2 P3
0 20 22 23
Gantt Chart
P2 P3 P1
0 2 3 23
The system will take extra 1 unit of time (overhead) after the execution of
every process to schedule the next process.
Efficiency= (1 - useless time/total CT) X 100= (1-(2/11)) X 100= 81.8
Shortest Job First (SJF)
Criteria:- Burst Time
Mode :- non- preemptive
Data Structure :- min-heap
Time complexity :- O(nlogn)
Tie break:- FCFS scheduling
In SJF scheduling, the process with the lowest burst time, among the
list of available processes in the ready queue, is going to be scheduled
first.
However, it is very difficult to predict the burst time needed for a
process hence this algorithm is very difficult to implement in the
system.
Example
P1 6 2 9 7 1
P2 2 5 11 6 4
P3 8 1 23 22 14
P4 3 0 3 3 0
P5 4 4 15 11 7
Non-preemptive
At time t=0, P4 is the only process present in ready queue, so assign P4 to
CPU. BT left for P4= 2.
At time t=1, P3 arrived, Now select between P4 P3, Sort processes based
on BT ( P4(2) P3(8)) Assign P4 to CPU. BT left for P4= 1.
Contd…
At time t=2, P1 arrived, Now select between P3 P1 P4, Sort
processes based on BT (P4(1) P1(6) P3(8)), Assign P4 to CPU.
P4 completes its execution. P4 completes its execution.
At time t=3, No new process arrived, Select between P1 P3
in ready queue, Sort processes based on BT (P1(6) P3(8)),
Assign CPU to P1. P1 completes its execution.
At time t=9, Select between P3 P2 P5, Sort processes based
on BT (P2(2) P5(4) P3(8)), Assign CPU to processes in the
following order P2 P5 P3.
P1 6 2 15 13 7
Preemptive P2 2 5 7 2 0
P3 8 1 23 22 14
P4 3 0 3 3 0
P5 4 4 10 6 2
At time t=0, P4 is the only process present in ready queue, so assign P4
to CPU. BT left for P4=2
At time t=1, P3 has arrived, Select between P3 P4, Sort processes based
on BT (P4(2) P3(8)), P4 will keep the CPU. BT left for P4=1
At time t=2, P1 has arrived, Select between P1 P3 P4, Sort processes
based on BT (P4(1) P1(6) P3(8)), P4 will keep the CPU. P4 completes its
execution.
Contd…
At time t=3, no new process, Select between P1 P3, Sort processes
based on BT (P1(6) P3(8)) Assign P1 to CPU. BT left for P1=5.
At time t=4, P5 has arrived, Select between P1 P3 P5, Sort processes
based on BT (P5(4) P1(5) P3(8)), Assign P5 to CPU. BT left for P5=3.
At time t=5, P2 has arrived, Select between P1 P3 P5 P2, sort processes
based on BT (P2(2) P5(3) P1(5) P3(8)), follow this sequence for
assignment of CPU.
Response Time (RT) P1: 3-2=1 P2: 5-5=0 P3:
15-1=14 P4: 0-0=0 P5: 4-4=0
Average TAT = 46/5=9.2
Average WT = 23/5=4.6
Throughput = 5/23
Thank You