Cpu Scheduling: by Noordiana Binti Kassim at Kasim / Mohd Hanif Bin Jofri / Ceds Uthm
Cpu Scheduling: by Noordiana Binti Kassim at Kasim / Mohd Hanif Bin Jofri / Ceds Uthm
By
Noordiana binti Kassim @ Kasim / Mohd Hanif bin Jofri / CeDS UTHM
Multiple
Basic Processor
Concept Scheduling
Real
Scheduling
CPU Time
CPU
Criteria
SCHEDULING Scheduling
Operating
Scheduling Systems
Algorithms Examples
To CPU scheduling, which is the basis for
Introduce 1 multiprogrammed operating systems.
To
Describe 2 various CPU-scheduling algorithms
To
Examine
3 the scheduling algorithms of
several operating systems
OBJECTIVES
WHAT IS CPU SCHEDULING?
Execution of the process is interrupted in the middle.Execution of the process remains uninterrupted until it
is completed.
The concept bears an overhead of switching between No such overhead of switching between the tasks.
the tasks.
If the CPU receives continuous high priority tasks, a If the CPU is processing a program with the largest
process may remain in the waiting state indefinitely. burst time, even a program with the smallest burst time
may have to starve.
It allows flexibility to the processes which are in the This approach is also known as the rigid scheduling as
waiting state allowing the high priority tasks to be it offers no flexibility to the processes irrespective of
executed first. their urgency for execution.
Pre emptive scheduling needs to maintain the The Non- pre-emptive Scheduling does not require to
integrity of the shared data and to ensure no data loss maintain data integrity as no processes are swapped
occurs when processes are swapped from the waiting from the waiting state to the ready state.
state to the ready state.
WHAT DO WE WANT TO ACHIEVE FROM
SCHEDULING (OBJECTIVES):
MAX MIN TIME TAKEN BY A
KEEP CPU AS BUSY
CPU 1 Turnaround4 PROCESS TO FINISH
Utilization AS POSSIBLE EXECUTION
Time
Max Throughput
Etc … processes moved by the dispatcher of the OS to the CPU then back to the
queue until the task is completed
CPU SCHEDULING
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
To decide which process to execute first and which process to execute last
P1 P2 P3
0 24 27 30
P2 P3 P1
0 3 6 30
Advantages:
• FCFS algorithm doesn't include any complex logic, it just puts the process
requests in a queue and executes it one by one.
• Hence, FCFS is pretty simple and easy to implement.
• Eventually, every process will get a chance to run, so starvation doesn't
occur.
Disadvantages:
• There is no option for pre-emption of a process. If a process is started, then
CPU executes the process until it ends.
• Because there is no pre-emption, if a process executes for a long time, the
processes in the back of the queue will have to wait for a long time before
they get a chance to be executed.
Shortest-Job-First (SJF) Scheduling
P4 P1 P3 P2
0 3 9 16 24
Shortest Job First scheduling works on the process with the shortest burst time
or duration first.
This is the best approach to minimize waiting time.
To successfully implement it, the burst time/duration time of the processes
should be known to the processor in advance, which is practically not feasible
all the time.
This scheduling algorithm is optimal if all the jobs/processes are available at the
same time.
SHORTEST JOB FIRST (SJF)
Advantages:
• According to the definition, short processes are executed first and then followed by longer
processes.
• The throughput is increased because more processes can be executed in less amount of
time.
Disadvantages:
• The time taken by a process must be known by the CPU beforehand, which is not possible.
• Longer processes will have more waiting time, eventually they'll suffer starvation.
ROUND ROBIN SCHEDULING (RR)
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
Advantages:
• Each process is served by the CPU for a fixed time quantum, so all
processes are given the same priority.
• Starvation doesn't occur because for each round robin cycle, every
process is given a fixed time to execute. No process is left behind.
Disadvantages:
• The throughput in RR largely depends on the choice of the length of the
time quantum. If time quantum is longer than needed, it tends to exhibit the
same behavior as FCFS.
• If time quantum is shorter than needed, the number of times that CPU
switches from one process to another process, increases. This leads to
decrease in CPU efficiency.
Multiple-Processor Scheduling