Professional Documents
Culture Documents
Operating System Concepts – 10h Edition Silberschatz, Galvin and Gagne ©2018
1.2
Learning Objectives
▪ After completing this chapter, you should be able to describe:
• The difference between job scheduling and process scheduling,
and how they relate
• The advantages and disadvantages of process scheduling
algorithms that are preemptive versus those that are non-
preemptive
• The goals of process scheduling policies in single-core CPUs
• Six different process scheduling algorithms
• The role of internal interrupts and the tasks performed by the
interrupt handler
Introduction
▪ The Processor Manager is responsible for allocating the processor to execute
the incoming jobs, and the tasks of those jobs
▪ However, the SJN algorithm is optimal only when all of the jobs are available at
the same time and the CPU estimates are available and accurate
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.15
Priority Scheduling
▪ a nonpreemptive algorithm that gives preferential treatment to important jobs.
▪ This algorithm (mostly common in batch systems) allows the programs with
the highest priority to be processed first, interrupted until their CPU cycles
(run times) are completed or a natural wait occurs.
▪ What happens to jobs with equal priority values?
• the CPU allocated to the one that arrived first (first-come, first-served
within priority).
▪ Priorities can be assigned by a system administrator using characteristics
extrinsic to the jobs.
▪ jobs are usually linked to one of several READY queues by the Job
Scheduler based on their priority so the Process Scheduler manages multiple
READY queues instead of just one
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.16
Priority Scheduling . . .
▪ Priorities can also be determined by the Processor Manager
based these following criteria:
1. Memory requirements.
2. Number and type of peripheral devices.
3. Total CPU time.
4. Amount of time already spent in the system… This is
known as aging.
Arrival Time 0 1 2 3
Job A B C D
CPU Cycle 6 3 1 4
▪ In this case, the turnaround time is the completion time of each job minus its
arrival time:
Job A B C D
Turnaround ? ? ? ?
▪ In this case, the turnaround time is the completion time of each job minus its
arrival time:
Job A B C D
Turnaround 14 ? ? ?
▪ In this case, the turnaround time is the completion time of each job minus its
arrival time:
Job A B C D
Turnaround 14 4 ? ?
▪ In this case, the turnaround time is the completion time of each job minus its
arrival time:
Job A B C D
Turnaround 14 4 1 ?
▪ In this case, the turnaround time is the completion time of each job minus its
arrival time:
Job A B C D
Turnaround 14 4 1 6
Job A B C D
Turnaround 14 4 1 6
Written Assignment
▪ How does the same jobs below compare to the same problem using the
nonpreemptive SJN policy?
Arrival Time 0 1 2 3
Job A B C D
CPU Cycle 6 3 1 4
Round Robin
▪ a preemptive scheduling algorithm used extensively in interactive systems.
▪ Based on a predetermined slice of time that’s given to each job to ensure that
the CPU is equally shared among all active processes and isn’t monopolized by
any one job
▪ This time slice is called a time quantum and usually varies from 100
milliseconds to 1 or 2 seconds
▪ Jobs are placed in the READY queue using a first-come, first-served (FIFO)
scheme
▪ The first job is selected from the front of the queue, sets the timer to the
time quantum, and allocates the CPU to this job.
▪ On expiration of the time quantum, if processing isn’t finished, the job is
preempted and put at the end of the READY queue and its information is saved
in its PCB. Next job is given the CPU
Silberschatz, et al, Operating System Concepts Compiled by: Samuel Banning
1.27
Round Robin . . .
▪ If a job’s CPU cycle is shorter than the time quantum, one of two
actions will take place:
1. If this is the job’s last CPU cycle and the job is finished, then
all resources allocated to it are released and the completed
job is returned to the user;
2. if the CPU cycle has been interrupted by an I/O request, then
information about the job is saved in its PCB and it is linked
at the end of the appropriate I/O queue. Later, when the I/O
request has been satisfied, it is returned to the end of the
READY queue to await allocation of the CPU
Round Robin . . .
▪ The following example illustrates a round robin algorithm with a time slice of
4 milliseconds (I/O requests are ignored):
Arrival Time 0 1 2 3
Job A B C D
CPU Cycle 8 4 9 5
The turnaround time is the completion time minus the arrival time:
Job A B C D
Turnaround ? ? ? ?
▪ The following example illustrates a round robin algorithm with a time slice of
4 milliseconds (I/O requests are ignored):
Arrival Time 0 1 2 3
Job A B C D
CPU Cycle 8 4 9 5
The turnaround time is the completion time minus the arrival time:
Job A B C D
Turnaround 20 ? ? ?
Round Robin . . .
▪ The following example illustrates a round robin algorithm with a time slice of
4 milliseconds (I/O requests are ignored):
Arrival Time 0 1 2 3
Job A B C D
CPU Cycle 8 4 9 5
The turnaround time is the completion time minus the arrival time:
Job A B C D
Turnaround 20 7 ? ?
Round Robin . . .
▪ The following example illustrates a round robin algorithm with a time slice of
4 milliseconds (I/O requests are ignored):
Arrival Time 0 1 2 3
Job A B C D
CPU Cycle 8 4 9 5
The turnaround time is the completion time minus the arrival time:
Job A B C D
Turnaround 20 7 24 ?
Round Robin . . .
▪ The following example illustrates a round robin algorithm with a time slice of
4 milliseconds (I/O requests are ignored):
Arrival Time 0 1 2 3
Job A B C D
CPU Cycle 8 4 9 5
The turnaround time is the completion time minus the arrival time:
Job A B C D
average turnaround
time?
Turnaround 20 7 24 22
Round Robin . . .
▪ The following example illustrates a round robin algorithm with a time slice of
4 milliseconds (I/O requests are ignored):
Arrival Time 0 1 2 3
Job A B C D
CPU Cycle 8 4 9 5
The turnaround time is the completion time minus the arrival time:
average turnaround time?
Job A B C D
Turnaround 20 7 24 22
Round Robin . . .
▪ The efficiency of round robin depends on the size of the time
quantum in relation to the average CPU cycle.
• If the quantum is too large—that is, if it’s larger than most
CPU
cycles—then the algorithm reduces to the FCFS scheme.
• If the quantum is too small, then the amount of context
switching slows down the execution of the jobs
Multiple-Level Queues
▪ Not really a separate scheduling algorithm but works in conjunction with several of the
schemes already discussed
▪ found in systems with jobs that can be grouped according to a common characteristic
• Recall: priority-based system with different queues for each priority level.
▪ Another kind of system might gather all CPU-bound jobs in one queue and all
I/O-bound jobs in another.
• The Process Scheduler then alternately selects jobs from each queue to keep the
system balanced
▪ A third common example is one used in a hybrid environment that supports both
batch and interactive jobs.
• The batch jobs are put in one queue called the background queue while the
interactive jobs are put in a foreground queue and are treated more favorably than
those on the background queue.
Conclusion
▪ The Processor Manager owes the CPU to all the system’s
users.
▪ In this chapter we’ve made the distinction between
• job scheduling,
• the selection of incoming jobs based on their
characteristics, and
• process scheduling,
• the instant-by-instant allocation of the CPU.