Scheduling Algorithms What Is CPU Scheduling?: "Best"
Scheduling Algorithms What Is CPU Scheduling?: "Best"
Arrival time
Arrival time is the time when a process enters into the ready state and is ready for
its execution.
Here in the above example, the arrival time of all the 3 processes are 0 ms, 1 ms,
and 2 ms respectively.
Exit time
Exit time is the time when a process completes its execution and exit from the
system.
Response time
Response time is the time spent when the process is in the ready state and gets the
CPU for the first time. For example, here we are using the First Come First Serve
CPU scheduling algorithm for the below 3 processes:
P1: 0 ms
P2: 7 ms because the process P2 have to wait for 8 ms during the execution
of P1 and then after it will get the CPU for the first time. Also, the arrival
time of P2 is 1 ms. So, the response time will be 8-1 = 7 ms.
P3: 13 ms because the process P3 have to wait for the execution of P1 and
P2 i.e. after 8+7 = 15 ms, the CPU will be allocated to the process P3 for
the first time. Also, the arrival of P3 is 2 ms. So, the response time for P3
will be 15-2 = 13 ms.
Response time = Time at which the process gets the CPU for the first time -
Arrival time
Waiting time
Waiting time is the total time spent by the process in the ready state waiting for
CPU. For example, consider the arrival time of all the below 3 processes to be 0
ms, 0 ms, and 2 ms and we are using the First Come First Serve scheduling
algorithm.
Then the waiting time for all the 3 processes will be:
P1: 0 ms
P2: 8 ms because P2 have to wait for the complete execution of P1 and
arrival time of P2 is 0 ms.
P3: 13 ms becuase P3 will be executed after P1 and P2 i.e. after 8+7 = 15
ms and the arrival time of P3 is 2 ms. So, the waiting time of P3 will be:
15-2 = 13 ms.
Waiting time = Turnaround time - Burst time
In the above example, the processes have to wait only once. But in many other
scheduling algorithms, the CPU may be allocated to the process for some time
and then the process will be moved to the waiting state and again after some time,
the process will get the CPU and so on.
There is a difference between waiting time and response time. Response time is
the time spent between the ready state and getting the CPU for the first time. But
the waiting time is the total time taken by the process in the ready state.
Turnaround time
Turnaround time is the total amount of time spent by the process from coming in
the ready state for the first time to its completion.
or
For example, if we take the First Come First Serve scheduling algorithm, and the
order of arrival of processes is P1, P2, P3 and each process is taking 2, 5, 10
seconds. Then the turnaround time of P1 is 2 seconds because when it comes at
0th second, then the CPU is allocated to it and so the waiting time of P1 is 0 sec
and the turnaround time will be the Burst time only i.e. 2 seconds. The
turnaround time of P2 is 7 seconds because the process P2 have to wait for 2
seconds for the execution of P1 and hence the waiting time of P2 will be 2
seconds. After 2 seconds, the CPU will be given to P2 and P2 will execute its
task. So, the turnaround time will be 2+5 = 7 seconds. Similarly, the turnaround
time for P3 will be 17 seconds because the waiting time of P3 is 2+5 = 7 seconds
and the burst time of P3 is 10 seconds. So, turnaround time of P3 is 7+10 = 17
seconds.
Different CPU scheduling algorithms produce different turnaround time for the
same set of processes. This is because the waiting time of processes differ when
we change the CPU scheduling algorithm.
Throughput
Throughput is a way to find the efficiency of a CPU. It can be defined as the
number of processes executed by the CPU in a given amount of time. For
example, let's say, the process P1 takes 3 seconds for execution, P2 takes 5
seconds, and P3 takes 10 seconds. So, throughput, in this case, the throughput
will be (3+5+10)/3 = 18/3 = 6 seconds.
What is Dispatcher?
A dispatcher is a special program which comes into play after the scheduler. When
the scheduler completes its job of selecting a process, it is the dispatcher which
takes that process to the desired state/queue. The dispatcher is the module that
gives a process control over the CPU after it has been selected by the short-term
scheduler. This function involves the following:
1. Switching context
2. Switching to user mode
3. Jumping to the proper location in the user program to restart that program
Example:
There are 4 processes in the ready queue, P1, P2, P3, P4; Their arrival times are t0,
t1, t2, t3 respectively. A First in First out (FIFO) scheduling algorithm is used.
Because P1 arrived first, the scheduler will decide it is the first process that should
be executed, and the dispatcher will remove P1 from the ready queue and give it to
the CPU. The scheduler will then determine P2 to be the next process that should
be executed, so when the dispatcher returns to the queue for a new process, it will
take P2 and give it to the CPU. This continues in the same way for P3, and then P4.
Properties DISPATCHER SCHEDULER
Scheduler is something
Dispatcher is a module that gives which selects a process
control of CPU to the process among various
Definition: selected by short term scheduler processes
Scheduler works on
Dispatcher has no specific various algorithm such
Algorithm: algorithm for its implementation as FCFS, SJF, RR etc.
Scheduling Algorithms
To decide which process to execute first and which process to execute last to
achieve maximum CPU utilization, computer scientists have defined some
algorithms are:
Non-Preemptive Scheduling
Under non-preemptive scheduling, once the CPU has been allocated to a process,
the process keeps the CPU until it releases the CPU either by terminating or by
switching to the waiting state.
This scheduling method is used by the Microsoft Windows 3.1 and by the Apple
Macintosh operating systems.
It is the only method that can be used on certain hardware platforms, because It
does not require the special hardware (for example: a timer) needed for preemptive
scheduling.
Preemptive Scheduling:
In this type of Scheduling the tasks are usually assigned with priorities. At times it
is necessary to run a certain task that has a higher priority before another task
although it is running. Therefore, the running task is interrupted for some time and
resumed later when the priority task has finished its execution.
First Come First Serve (FCFS)
P1 5-1=4
P2 8-2=6
P3 16 - 3 = 13
P0 3-0=3
P1 0-0=0
P2 16 - 2 = 14
P3 8-3=5
P0 9-0=9
P1 6-1=5
P2 14 - 2 = 12
P3 0-0=0
P1 (3 - 1) = 2
P3 (9 - 3) + (17 - 12) = 11
The definition of a multilevel feedback queue scheduler makes it the most general
CPU-scheduling algorithm. It can be configured to match a specific system under
design. Unfortunately, it also requires some means of selecting values for all the
parameters to define the best scheduler. Although a multilevel feedback queue is
the most general scheme, it is also the most complex.