29
Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling • Process concept • Process scheduling • Interprocess communication • Deadlocks • Threads

Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept Process scheduling Interprocess communication Deadlocks Threads

  • View
    220

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-1

Chapter 2.2 : Process Scheduling

• Process concept • Process scheduling

• Interprocess communication

• Deadlocks

• Threads

Page 2: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-2

Scheduling

• Select process(es) to run on processor(s)

• Process state is changed from “ready” to “running”

• The component of the OS which does the scheduling is called the scheduler

Page 3: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-3

Types of Scheduling• Scheduling is divided into various levels.

• These levels are defined by the location of the processes

• A process can be – available to be executed by the processor– partially or fully in main memory– in secondary memory– is not started yet

Page 4: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-4

Types of Scheduling• Long Term Scheduling.

– The decision to add to the pool of processes to be executed.

• Medium Term Scheduling.– The decision to add to the process in main memory.

• Short Term Scheduling.– The decision as to which process will gain the processor.

• I/O Scheduling.– The decision as to which process's I/O request shall be

handled by a device.

Page 5: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-5

Scheduling Criteria

• Fairness : each process should get a fair share of the CPU

• Efficiency: keep CPU 100% utilized• Response time : should be minimized for

interactive users• Turnaround : minimize batch turnaround

times• Throughput : maximize number of jobs

processed per hour

Page 6: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-6

User-Oriented, Performance Criteria

Criteria AimResponse Time low response time,

maximum number of interactive users

Turnaround Time time between submission and completion

Deadlines maximise deadlines met

Page 7: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-7

System-oriented, Performance Criteria

Criteria Aim•Throughput allow maximum number of jobs to complete

•Processor maximise percentage of time processor is busy

utilisation

•Overhead minimise time processor busy executing OS

Page 8: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-8

System oriented, other criteria

Criteria Aim

Fairness treat processes the same avoid starvation

Enforcing Priorities give preference to higher priority processes

Balancing Resources keep the system resources busy

Page 9: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-9

Important Factors• I/O boundedness of a process• CPU boundedness of a process• Is the process interactive or batch?• Process priority• Page fault frequency• Preemption frequency• Execution time received• Execution time required to complete

Page 10: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-10

Types of Scheduling

• A scheduling algorithm is non-premptive (run to completion) if the CPU cannot be taken away by the OS.

• A scheduling algorithm is preemptive if the CPU can be taken away by the OS.

Page 11: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-11

The Interrupting Clock

• The OS sets the interrupting clock to generate an interrupt at some specified future time.

• This interrupt time is the process quantum.

• Provides reasonable response times and prevents the system being held up by processes in infinite loops.

Page 12: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-12

Scheduling Algorithms

• FCFS • Round Robin• Virtual Round Robin• Priority • Priority Classes• Shortest Job First• Shortest Remaining Time• Highest Response Ratio Next• Feedback Queues

Page 13: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-13

FCFS (First Come First Serve)

• Implementation:– As each process becomes ready, it joins the

ready queue. – When the current process finishes the oldest

process is selected next.

• Characteristics:– Simple to implement– Nonpremptive– Penalises short and I/O-bound processes

Page 14: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-14

Round Robin (RR)

• Implementation:– Processes are dispatched FIFO. But are given a

fixed time on the CPU (quantum - time slice).

• Characteristics:– Preemptive– Effective in time sharing environments– Penalises I/O bound processes

Page 15: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-15

Quantum Size• Some Options:

– Large or small quantum– Fixed or variable quantum– Same for everyone or different– If quantum is to large RR degenerates into

FCFS– If quantum is to small context switching

becomes the primary job being executed• A good guide is quantum should be slightly

larger than the time required for a typical interaction

Page 16: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-16

Virtual Round Robin (VRR)• A modification to the RR algorithm to remove

the bias towards CPU bound processes.

• Implementation:– Two “ready” queues, one called an AUX

queue for storing “completed” IO processes– AUX queue has priority over READY queue– IO processes only runs for remaining time

• Characteristics:– Performance studies indicate fairer than RR

Page 17: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-17

Priority• Implementation:

– Each process is assigned a priority and the scheduler always selects the highest priority process first

• Characteristics:– High priority processes may run indefinitely, so

decrease the priority of these processes at regular intervals

– Assign high priority to system processes with known characteristics such as being I/O bound

Page 18: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-18

Priority Classes

Priority Class 4

Priority Class 2

Priority Class 1

Priority Class 3

Highest

Lowest

Page 19: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-19

• Implementation:– Processes are grouped into priority classes– Round Robin is used within a class– When selecting process start with the highest

class. If the class is empty, use a lower class

• Characteristics:– If priorities are not adjusted from time to time,

lower classes may starve to death

Page 20: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-20

Shortest-Job-First (SJF)• Sometimes known as Shortest Process Next

(SPN)

• Implementation:

–The process with the shortest expected execution time is given priority on the processor

Page 21: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-21

• Characteristics:– Nonpremptive– Reduces average waiting time over FIFO– Always produces the minimum average

turnaround time– Must know how long a process will run– Possible user abuse– Suitable for batch environments. Not useful in a

timesharing environment

Page 22: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-22

Shortest Remaining Time (SRT)

• Preemptive counterpart of SPN

• Implementation:–Process with the smallest estimated run-

time to completion is run next–A running process may be preempted by a

new process with a shorter estimate run-time

Page 23: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-23

• Characteristics:– Still requires estimates of the future– Higher overhead than SJF– No additional interrupts are generated as

in RR– Elapsed service times must be recorded

Page 24: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-24

Highest Response Ratio Next (HRRN)• How do you get around the problem of

Indefinite postponement?

• Implementation:– Once a job gets the CPU it runs it to completion– The priority of a job is a function of the job's

service time and the time it has been waiting for service

priority = (time waiting + service time) / service time

Page 25: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-25

• Characteristics:

–Nonpremptive

–Shorter jobs still get preference over longer jobs

–However aging ensures long jobs will eventually gain the processor

–Estimation still involved

Page 26: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-26

Feedback Queues

• Sometimes called multi-level feedback queues

• Implementation:

–There is a network of ready queues

–A new process enters at the top queue

–Moves through the queue FIFO

Page 27: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-27

• I/O processes:

–If the job requires I/O before quantum expiration it leaves the network and comes back at the same level queue

• CPU bound processes:

–If the quantum expires first, the process is placed on the next lower queue

–This continues until it reaches the bottom queue

Page 28: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-28

• Dispatching:–A process is only placed on the CPU

if all higher level queues are empty–A running process is preempted by a

process arriving in a higher queue–Processes from lower level queues

receive a larger quantum• Modifications:

–In some systems processes can proceed back up the network by becoming I/O bound

Page 29: Ceng 334 - Operating Systems 2.2-1 Chapter 2.2 : Process Scheduling Process concept  Process scheduling Interprocess communication Deadlocks Threads

Ceng 334 - Operating Systems 2.2-29

A Scheduling Mechanism Should:

• Favour short jobs

• Favour I/O bound jobs to get good I/O device utilisation

• Determine the nature of a job and schedule accordingly