Download as pdf or txt
Download as pdf or txt
You are on page 1of 64

Chapter 4

Processor Management

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
1
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Learning Objectives
After completing this chapter, you should be able to describe:
• How job scheduling and process scheduling compare
• How several process scheduling algorithms work
• How the process scheduling policies can be implemented
• How processes and threads compare
• How the interrupt handler manages pauses in processing

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
2
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Overview
• Simple system
o Single user
o One processor: busy only when executing the user’s job or system software
• Multi programming environment: multiple processes competing to be run by a
single CPU
o Requires fair and efficient CPU allocation for each job
• Single processor systems
o Addressed in this chapter

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
3
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Definitions (1 of 3)
• Processor (CPU)
o Performs calculations and executes programs
• Program (job)
o Inactive unit, e.g., file stored on a disk
o Unit of work submitted by the user
• Process (task)
o Active entity
• Requires resources (processor, special registers, etc.) to perform function
o Executable program single instance

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
4
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Definitions (2 of 3)
• Thread
o Portion of a process
o Runs independently
• Multithreading
o Allows applications to manage a separate process with several threads of control
o Example: Web browsers
• Multiprogramming
o Processor allocated to each job or each process for a time period
o Deallocated at appropriate moment: delicate task

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
5
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Definitions (3 of 3)
• Interrupt
o Call for help
o Activates higher-priority program
• Context switch
o Saving job processing information when interrupted
• Completed jobs
o Finished or terminated
• Single processor
o May be shared by several jobs (processes)
o Requires scheduling policy and scheduling algorithm

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
7
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
About Multi-Core Technologies
• Dual-core, quad-core, or other multi-core CPU
o More than one processor (core): located on computer chip
• Single chip may contain multiple cores
o Multi-core engineering
• Resolves leakage and heat problems
• Multiple calculations may occur simultaneously
• More complex Processor Manager handling: discussed in Chapter 6

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
8
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Scheduling Submanagers (1 of 2)
• Processor Manager: composite of two submanagers
• Job Scheduler and Process Scheduler: hierarchical scheduling system
• Job Scheduler: higher-level scheduler
o Job scheduling responsibilities
o Job initiation based on certain criteria
• Process Scheduler: lower-level scheduler
o Process scheduling responsibilities
o Determines execution steps
o Process scheduling: based on certain criteria

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
9
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Scheduling Submanagers (2 of 2)
• Job Scheduler functions
o Selects incoming job from queue
o Places in process queue
o Decides on job initiation criteria
• Process scheduling algorithm and priority
• Goal
o Sequence jobs
• Efficient system resource utilization
o Balance I/O interaction and computation
o Keep most system components busy most of time

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
10
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Process Scheduler (1 of 4)
• Process Scheduler functions
o Determines job to get CPU resource
• When and how long
o Decides interrupt processing
o Determines queues for job movement during execution
o Recognizes job conclusion
• Determines job termination
• Lower-level scheduler in the hierarchy
o Assigns CPU to execute individual actions: jobs placed on READY queue by the
Job Scheduler

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
11
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Process Scheduler (2 of 4)
• Exploits common computer program traits
o Programs alternate between two cycles
• CPU and I/O cycles
• Frequency and CPU cycle duration vary
• General tendencies
o I/O-bound job
• Many brief CPU cycles and long I/O cycles (printing documents)
o CPU-bound job
• Many long CPU cycles and shorter I/O cycles (math calculation)

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
12
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Process Scheduler (3 of 4)

(figure 4.2)
Distribution of CPU cycle times. This
distribution shows a greater number of jobs
requesting short CPU cycles (the frequency
peaks close to the low end of the CPU cycle
axis), and fewer jobs requesting long CPU
cycles.

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
13
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Process Scheduler (4 of 4)
• Middle-level scheduler: third layer
• Found in highly interactive environments
o Handles overloading
• Removes active jobs from memory
• Reduces degree of multiprogramming
o Results in faster job completion
• Single-user environment
o No distinction between job and process scheduling
o One job active at a time
• Receives dedicated system resources for job duration

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
14
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Job and Process States (1 of 5)
• Status changes: as a job or process moves through the system
o HOLD
o READY
o WAITING
o RUNNING
o FINISHED
• Referred to as job status or process status, respectively

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
15
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Job and Process States (2 of 5)
(figure 4.3)
A typical job (or process) changes status as it moves through the system from HOLD to
FINISHED.

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
16
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Job and Process States (3 of 5)
• User submits job
o Job accepted
• Put on HOLD and placed in queue
o Job state changes from HOLD to READY
• Indicates job waiting for CPU
o Job state changes from READY to RUNNING
• When selected for CPU and processing
o Job state changes from RUNNING to WAITING
• Requires unavailable resources: moves back to READY status
o Job state changes to FINISHED
• Job completed (successfully or unsuccessfully)

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
17
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Job and Process States (4 of 5)
• Job Scheduler or Process Scheduler incurs state transition responsibility
o HOLD to READY
• Job Scheduler initiates using predefined policy
o READY to RUNNING
• Process Scheduler initiates using predefined algorithm
o RUNNING back to READY
• Process Scheduler initiates according to predefined time limit or other criterion
o RUNNING to WAITING
• Process Scheduler initiates by instruction in job

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
18
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Job and Process States (5 of 5)
• Job Scheduler or Process Scheduler incurs state transition responsibility
(continued)
o WAITING to READY
• Process Scheduler initiates by signal from I/O device manager
• Signal indicates I/O request satisfied; job continues
o RUNNING to FINISHED
• Process Scheduler or Job Scheduler initiates upon job completion
• Satisfactorily or with error

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
19
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Thread States (1 of 6)
• Five states as a thread moves through the system
o READY
o RUNNING
o WAITING
o DELAYED
o BLOCKED
• Thread transitions
o Application creates a thread: placed in READY queue
o READY to RUNNING: Process Scheduler assigns it to a processor

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
20
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Thread States (2 of 6)
(figure 4.4)
A typical thread changes states several times as it moves from READY to FINISHED.

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
21
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Thread States (3 of 6)
• Thread transitions
o Application creates a thread: placed in READY queue
o READY to RUNNING: Process Scheduler assigns it to a processor
o RUNNING to WAITING: when dependent on an outside event, e.g., mouse click,
or waiting for another thread to finish
o WAITING to READY: outside event occurs or previous thread finishes

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
22
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Thread States (4 of 6)
• Thread transitions
o RUNNING to DELAYED: application that delays thread processing by specified
amount of time
o DELAYED to READY: prescribed time elapsed
o RUNNING to BLOCKED: I/O request issued
o BLOCKED to RUNNING: I/O completed
o RUNNING to FINISHED: exit or termination
• All resources released

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
23
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Thread States (5 of 6)
• Operating systems must be able to:
o Create new threads
o Set up a thread so it is ready to execute
o Delay, or put to sleep, threads for a specified amount of time
o Block, or suspend, threads waiting for I/O to be completed
o Set threads to a WAIT state until a specific event occurs
o Schedule threads for execution

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
24
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Thread States (6 of 6)
• Operating systems must be able to:
o Synchronize thread execution using semaphores, events, or conditional variables
o Terminate a thread and release its resources

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
25
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Control Blocks (1 of 2)
• Process Control Block (PCB): data structure for each process in the system
• Thread Control Block (TCB): data structure for each thread

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
26
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Control Blocks (2 of 2)
(figure 4.5)
Comparison of a typical thread control block (TCB) (left) versus a process control block (PCB) (right).

Thread identification Process identification


Thread state Process status
CPU information: Process state:
Program counter Process status word
Register contents Register contents
Thread priority Main memory
Pointer to process that created this thread Resources
Pointers to all other threads created by this Process priority
thread Accounting

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
27
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Control Blocks and Queuing (1 of 2)
• Job PCB
o Created when Job Scheduler accepts job
o Updated as job executes
o Queues use PCBs to track jobs
o Contains all necessary job management processing data
o PCBs linked to form queues (jobs not linked)
• PCBs or TCBs: requires orderly management of queues
o Determined by process scheduling policies and algorithms

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
28
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Control Blocks and Queuing (2 of 2)
(figure 4.6)
Queuing paths from HOLD to FINISHED. The Job and Processor Schedulers release the resources when
the job leaves the RUNNING state.

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
29
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Scheduling Policies and Algorithms
• Multiprogramming environment
o More jobs than resources at any given time
• Operating system pre-scheduling task
o Resolve three system limitations
• Finite number of resources (disk drives, printers, tape drives)
• Some resources cannot be shared once allocated (printers)
• Some resources require operator intervention before reassigning

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
30
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Scheduling Policies (1 of 4)
• Good process scheduling policy criteria
o Maximize throughput
• Run as many jobs as possible in given amount of time
o Minimize response time
• Quickly turn around interactive requests
o Minimize turnaround time
• Move entire job in and out of system quickly
o Minimize waiting time
• Move job out of READY queue quickly

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
31
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Scheduling Policies (2 of 4)
• Good process scheduling policy criteria (continued)
o Maximize CPU efficiency
• Keep CPU busy 100 percent of time
o Ensure fairness for all jobs
• Give every job equal CPU and I/O time
• Final policy criteria decision lies with system designer or administrator

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
32
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Scheduling Policies (3 of 4)
• Problem
o Job claims CPU for very long time before I/O request issued
• Builds up READY queue and empties I/O queues
• Creates unacceptable system imbalance
• Corrective measure
o Interrupt
• Used by Process Scheduler upon predetermined expiration of time slice
• Current job activity suspended
• Reschedules job into READY queue

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
33
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Scheduling Policies (4 of 4)
• Types of scheduling policies
o Preemptive
• Used in time-sharing environments
• Interrupts job processing
• Transfers CPU to another job
o Nonpreemptive
• Functions without external interrupts
o Infinite loops interrupted in both cases

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
34
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Scheduling Algorithms
• Based on specific policy
o Allocates CPU and moves job through the system
• Most systems emphasize fast user response time
• Several algorithms
o First-come, first-served (FCFS)
o Shortest job next (SJN)
o Priority scheduling
o Shortest remaining time (SRT)
o Round robin
o Multiple-level queues
o Earliest deadline first (EDF)

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
35
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
First-Come, First-Served (1 of 2)
• Nonpreemptive
• Job handled based on arrival time
o Earlier job arrives, earlier served
• Simple algorithm implementation
o Uses first-in, first-out (FIFO) queue
Good for batch systems
• Unacceptable in interactive systems
o Unpredictable turnaround time
• Disadvantages
o Average turnaround time varies; seldom minimized

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
36
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
First-Come, First-Served (2 of 2)
(figure 4.7)
Timeline for job sequence A, B, C using the FCF S algorithm.

Note: Average turnaround time: 16.67

(figure 4.8)
Timeline for job sequence C, B, A using the FCFS algorithm.

Note: Average turnaround time: 7.3

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
37
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Shortest Job Next (1 of 2)
• Nonpreemptive
• Also known as shortest job first (SJF)
• Job handled based on length of CPU cycle time
• Easy implementation in batch environment
o CPU time requirement known in advance
• Does not work well in interactive systems
• Optimal algorithm
o All jobs are available at same time
o CPU estimates available and accurate

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
38
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Shortest Job Next (2 of 2)
(figure 4.9)
Timeline for job sequence B, D, A, C using the nonpreemptive SJN algorithm.

The users who using a batch operating system do not interact with the computer directly. Each user prepares its job on an off-line device like
punch cards and submits it to the computer operator. To speed up the processing, jobs with similar needs are batched together and run as a
group.Â

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
39
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Priority Scheduling (1 of 3)
• Nonpreemptive
• Preferential treatment for important jobs
o Highest priority programs processed first
o No interrupts until CPU cycles completed or natural wait occurs
• Process Scheduler: manages multiple READY queues
• System administrator or Processor Manager use different methods of
assigning priorities

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
40
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Priority Scheduling (2 of 3)
• Processor Manager priority assignment methods
o Memory requirements
• Jobs requiring large amounts of memory
• Allocated lower priorities (vice versa)
o Number and type of peripheral devices
• Jobs requiring many peripheral devices
• Allocated lower priorities (vice versa)

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
41
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Priority Scheduling (3 of 3)
• Processor Manager priority assignment methods (continued)
o Total CPU time
• Jobs having a long CPU cycle
• Given lower priorities (vice versa)
o Amount of time already spent in the system (aging)
• Total time elapsed since job accepted for processing
• Increase priority if job in system unusually long time

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
42
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Shortest Remaining Time (1 of 2)
• Preemptive version of SJN
• Processor allocated to job closest to completion
o Preemptive if newer job has shorter completion time
• Often used in batch environments
o Short jobs given priority
• Cannot implement in interactive system
o Requires advance CPU time knowledge
• Involves more overhead than SJN
o System monitors CPU time for READY queue jobs
o Performs context switching

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
43
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Shortest Remaining Time (2 of 2)
(figure 4.10)
Timeline for job sequence A, B, C, D using the preemptive SRT algorithm. Each job is
interrupted after one CPU cycle if another job is waiting with less CPU time remaining.

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
44
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Round Robin (1 of 7)
• Preemptive
• Used extensively in interactive systems
• Based on predetermined time slice (time quantum)
• Each job assigned time quantum
• Time quantum size
o Crucial to system performance
o Varies from 100 ms to 1 to 2 seconds
• CPU equally shared among all active processes
o Not monopolized by one job

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
45
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Round Robin (2 of 7)
• Job placed on READY queue (FCFS scheme)
• Process Scheduler selects first job
o Sets timer to time quantum
o Allocates CPU
• Timer expires
• If job CPU cycle > time quantum
o Job preempted and placed at end of READY queue
o Information saved in PCB

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
46
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Round Robin (3 of 7)
• If job CPU cycle < time quantum
o Job finished: allocated resources released and job returned to user
o Interrupted by I/O request: information saved in PCB and linked to I/O queue
• Once I/O request satisfied
o Job returns to end of READY queue and awaits CPU

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
47
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Round Robin (4 of 7)
(figure 4.12)
Timeline for job sequence A, B, C, D using the preemptive round robin algorithm with time
slices of 4 ms.

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
48
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Round Robin (5 of 7)
• Efficiency
o Depends on time quantum size
• In relation to average CPU cycle
• Quantum too large (larger than most CPU cycles)
o Algorithm reduces to FCFS scheme
• Quantum too small
o Context switching occurs
• Job execution slows down
• Overhead dramatically increased

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
49
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Round Robin (6 of 7)
(figure 4.13)
Context switches for three different time slices. In (a), Job A (which requires only 8 cycles to
run to completion) finishes before the time quantum of 10 expires, so Job B begins
immediately. In (b) and (c), the time quantum expires first, interrupting the jobs.

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
50
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Round Robin (7 of 7)
• Best quantum time size
o Depends on system
• Interactive: response time key factor
• Archival system: turnaround time key factor
o General rules of thumb
• Long enough for 80% of CPU cycles to complete
• At least 100 times longer than context switch time requirement

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
51
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Multiple-Level Queues
• Works in conjunction with several other schemes
• Works well in systems with jobs grouped by common characteristic
o Priority-based
• Different queues for each priority level
o CPU-bound jobs in one queue and I/O-bound jobs in another queue
o Hybrid environment
• Batch jobs in background queue
• Interactive jobs in foreground queue
• Scheduling policy based on predetermined scheme
• Four primary methods of moving jobs

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
52
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Case 1: No Movement Between Queues
• Simple
• Rewards high-priority jobs
o Processor allocated using FCFS
• Processor allocated to lower-priority jobs
o Only when high-priority queues empty
• Good environment
o Few high-priority jobs
o Spend more time with low-priority jobs

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
53
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Case 2: Movement Between Queues
• Processor adjusts priorities assigned to each job
• High-priority jobs
o Initial priority favorable
• Treated like all other jobs afterwards
• Quantum interrupt
o Job preempted
• Moved to next lower queue
• May have priority increased
• Good environment
o Jobs handled by cycle characteristics (CPU or I/O)
o Interactive systems

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
54
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Case 3: Variable Time Quantum Per Queue
• Case 2 variation: movement between queues
• Each queue given time quantum size
o Size twice as long as previous queue
• Fast turnaround for CPU-bound jobs
• CPU-bound jobs execute longer and given longer time periods
o Improves chance of finishing faster

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
55
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Case 4: Aging
• Ensures lower-level queue jobs eventually complete execution
• System keeps track of job wait time
• If too “old”:
o System moves job to next highest queue
o Continues until old job reaches top queue
o May drastically move old job to highest queue
• Advantage
o Guards against indefinite postponement
• Major problem: discussed further in Chapter 5

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
56
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Earliest Deadline First (1 of 2)
• Dynamic priority algorithm
• Preemptive
• Addresses critical processing requirements of
real-time systems: deadlines
• Job priorities can be adjusted while moving through the system
• Primary goal:
o Process all jobs in order most likely to allow each to run to completion before
reaching their respective deadlines

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
57
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Earliest Deadline First (2 of 2)
• Initial job priority: inversely proportional to its absolute deadline
o Jobs with same deadlines: another scheme applied
• Priority can change as more important jobs enter the system
• Problems
o Missed deadlines: total time required for all jobs greater than allocated time until
final deadline
o Impossible to predict job throughput: changing priority nature
o High overhead: continual evaluation of deadlines

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
58
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Managing Interrupts (1 of 3)
• Interrupt types
o Page interrupt (memory manager)
• Accommodate job requests
o Time quantum expiration interrupt
o I/O interrupt
• Result from READ or WRITE command issuance
o Internal interrupt (synchronous interrupt)
• Result from arithmetic operation or job instruction
o Illegal arithmetic operation interrupt
• Dividing by zero; bad floating-point operation, fixed-point operations resulting in
overflow or underflow

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
59
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Managing Interrupts (2 of 3)
• Interrupt types (continued)
o Illegal job instruction interrupt
• Attempting protected storage access, operating on invalid data, etc.
• Interrupt handler
o Control program
• Handles interruption event sequence

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
60
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Managing Interrupts (3 of 3)
• Nonrecoverable error detected by operating system
o Interrupt handler sequence
• Interrupt type described and stored
• Interrupted process state saved
• Interrupt processed
• Processor resumes normal operation

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
61
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Conclusion (1 of 3)
• Processor Manager allocates CPU among all users
• Job scheduling
• Based on characteristics
• Process and thread scheduling
o Instant-by-instant allocation of CPU
• Interrupt handler: generates and resolves interrupts
• Each scheduling algorithm is unique
o Characteristics, objectives, and applications
• System designer selects best policy and algorithm
o After careful strengths and weaknesses evaluation

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
62
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Conclusion (2 of 3)
(table 4.3)
Comparison of the Scheduling Algorithms Discussed in this Chapter.
© Cengage Learning 2018

Algorithm Policy Type Advantages Disadvantages


First Come, First Served Nonpreemptive Easy to implement Unpredictable turnaround
(FCFS) times; has an element of
chance
Shortest Job Next (SJN) Nonpreemptive Minimizes average waiting Indefinite postponement of
time some jobs; requires
execution times in advance

Priority Scheduling Nonpreemptive Ensures fast completion of Indefinite postponement of


important jobs some jobs
Shortest Remaining Preemptive Ensures fast completion of Overhead incurred by
Time (SRT) short jobs context switching

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
63
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Conclusion (3 of 3)
(table 4.3)
Comparison of the Scheduling Algorithms Discussed in this Chapter.
© Cengage Learning 2018

Algorithm Policy Type Advantages Disadvantages


Round Robin Preemptive Provides reasonable response times Requires selection of
to interactive users; provides fair CPU good time quantum
allocation
Multiple-Level Preemptive/Non- Flexible scheme; allows aging or Overhead incurred by
Queues preemptive other queue movement to counteract monitoring queues
indefinite postponement; fair to CPU-
bound jobs
Earliest Deadline Preemptive Attempts timely completion of jobs Overhead required to
First (EDF) monitor dynamic
deadlines

Mchoes/Flynn, Understanding Operating Systems, 8th Edition. © 2018 Cengage. All Rights Reserved.
64
May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

You might also like