INTRODUCTION
TO
OPERATING SYSTEMS
Lecture 9: PROCESS SCHEDULING (2)
CHRIS STAFF
Dept. of Computer Science and Artificial Intelligence
University of Malta
Lecture Outline
Aims and Objectives
Scheduling Algorithms
Aims and Objectives
- Different Scheduling Algorithms
Scheduling Algorithms
First-In-First-Out (FIFO)
- Processes selected in the order in which they entered the ready queue.
- Not pre-emptive.
- Process which voluntarily relinquishes control of CPU is added to end of
ready queue.
- Turnaround times cannot be guaranteed, so not good for interactive
environments.
- Resource utilisation can be poor and unevenly distributed.
- FIFO is fair in that all processes will eventually be executed, but it may
make important jobs and short jobs wait for whatever is ahead of them in the
queue.
- FIFO tends to be embedded in other schemes, e.g., priority-based algorithms
when all processes have the same priority.
Shortest-Job-First (SJF)
- Selects shortest job in the ready queue.
- Non-preemptive.
- OS needs to know estimated execution times of processes.
- Unfair on long jobs.
Shortest-Remaining-Time-Next (SRTN)
- Modification of SJN to allow preemption by shorter jobs entering the ready
queue.
- Long jobs have to wait even longer.
- SRTN has to calculate how much time is needed to complete the current job,
and then decide whether to switch processes if the new process is only a bit
shorter than the current one.
- SRTN (and SJN) try to maximise throughput.
Priority-Based Pre-emptive Scheduling
- Processes are given user- or system-defined prioity at creation
- Can reflect relative importance of process or user, type of resources
required, running time, etc. or a combination.
- Processes are sorted in ready queue, so that top priority process is at the
head of the queue.
- Current process can be pre-empted by higher priority process entering
queue.
- Two types of priority schemes
- Static - initial priority does not change
- Dynamic - priority can change over time, e.g., ageing. Guarantees completion
within finite time.
Round Robin (Time-Slice Scheduling)
- Tyipcally used in time-sharing or interactive environments, where good
terminal response time is important.
- Each runnable process in the system is given an equal time-slice (quantum) of
the CPU's time.
- When quantum expires, process is interrupted.
- Queue ordered according to order in which processes were created.
- A Hardware Clock is used to generate interrupts. Quantum size changes
dynamically.
- Round-Robin favours processes which complete within their time-slice.
- Quantum size is important, because too large a quantum will means that
processes can complete, but all other processes will have long to wait.
- If there are too many ready processes, then quantum size could be too small
for any process to do a significant amount of work before it is interrupted
(sudden load degradation).
Multiple-Level Queues (MLQ)
- Previous algorithms were good for processes displaying narrow behaviour
patterns, but other processes were punished.
- MLQs have 2 or more ready queues. Each queue contains processes that are
display similar behaviour patterns.
- The queues themselves have different priorities. Processes in the second
queue will only be process when the first queue is empty. A second queue
process will be pre-empted if a process enters the first queue.
- Thus, system processes can be allocate to the first queue, and therefore have
an implicit higher priority than any other process in the system.
- The second queue could hold interactive processes, and a third queue could
hold batch processes.
- Each queue could have a different scheduling algorithm, to reflect the best
order in which the contents of the queue should be processed (e.g.,
Priority-Based Pre-emptive Scheduling, Round-Robin, and FIFO).
- Disadvantage is processes are pre-assigned to queues, and no account is taken
of their behaviour during execution.
Mulitiple-Level Feedback Queues (MLFQ)
- An improvement on MLQs because process's run-time bevaviour pattern
influences the queue in which the process will be placed in the next execution
cycle.
- A newly created process is appended to highest-level queue.
- If the process voluntarily relinquishes control of the CPU, then it will stay
in the same queue.
- If the process is preempted, then it is relegated to a lower-priority
queue.
- In this way, while a process is entering an I/O-bound phase of execution, it
will occupy a high-priority queue, but when it enters a CPU-bound phase, it
will be relegated.
- Interactive processes will therefore achieve a good terminal response time,
while batch processes will only be executed if there are no other non-batch
processes in the system.
- This ensures a good mix of I/O- and CPU-bound processes, and ensures that I/O
and CPU are utilised even when there are no interactive processes in the system
(e.g., overnight).
Summary
- 7 scheduling algorithms, and how simple algorithms can be embedded within
more complex ones to give a richer scheduling environment
Next Lecture...
Memory Management (1)