Академический Документы
Профессиональный Документы
Культура Документы
Process Management
Objectives
To introduce CPU scheduling, which is the basis for multi
Process Management
Scheduling Concepts
Multiprogramming
Jobs
User
Process
Scheduling Behavior
Most Processes Dont Use Up Their Scheduling Quantum!
CPU bursts tend to have a frequency curve similar to the exponential curve
shown above. It is characterized by a large number of short CPU bursts and a
small number of long CPU bursts. An I/O-bound program typically has many
short CPU bursts; a CPU-bound program might have a few long CPU bursts.
Process Management
CPU Scheduler
The CPU scheduler selects from among the processes in memory that are ready to execute and
allocates the CPU to one of them
Process Management
The Dispatcher
Dispatcher module gives control of the CPU to the process selected by the short-
context
switching
to user mode
jumping
Dispatch latency time it takes for the dispatcher to stop one process and start
another running
Process Management
Process Scheduling
Maximize CPU use, quickly switch processes onto CPU
Process Management
Process Management
Process Management
Schedulers
I/O-bound process spends more time doing I/O than computations, many
short CPU bursts
CPU-bound process spends more time doing computations; few very long
CPU bursts
Process Management
Process Management
Remove process from memory, store on disk, bring back in from disk to continue execution:
swapping
Process Management
Long-Term Scheduling
Determines which programs are admitted to the system for processing
Controls the degree of multiprogramming
processes
CPU usage
System performance
Process Management
Medium-Term Scheduling
Makes swapping decisions based on the current degree of
multiprogramming
Process Management
Short-Term Scheduling
Selects from among ready processes in memory which one is to execute next
It is invoked on events that may lead to choose another process for execution:
Process Management
Clock interrupts
I/O interrupts
Signals
Preemptive
Currently
Prevents
Process Management
Process Management
Scheduling Criteria
Different CPU scheduling algorithms have different properties
The choice of a particular algorithm may favor one class of processes over
another
In choosing which algorithm to use, the properties of the various algorithms
should be considered
Criteria for comparing CPU scheduling algorithms may include the following
CPU utilization percent of time that the CPU is busy executing a process
Throughput number of processes that are completed per time unit
Response time amount of time it takes from when a request was
submitted until the first response occurs (but not the time it takes to output
the entire response)
Waiting time the amount of time before a process starts after first
entering the ready queue (or the sum of the amount of time a process has
spent waiting in the ready queue)
Turnaround time amount of time to execute a particular process from
the time of submission through the time of completion
Process Management
Optimization Criteria
It is desirable to
Maximize throughput
Process Management
Process Management
Process Management
Process Management
Batch Systems:
First Come First Served (FCFS)
Shortest Job First (SJF)
Shortest Remaining Time Next (SRTN)
Interactive Systems:
Round Robin (RR)
Priority
Multi level Queue
Multi level feedback queue
Shortest Process Next
Guaranteed Scheduling
Lottery Scheduling
Fair-Share Scheduling
P.V.S. Lakshmi Jagadamba
Process Management
Process Management
Burst Time
P1
24
P2
P3
The
Gantt
Chart
for
P1
the
P2
24
schedule
is:
P3
27
30
(24 + 27 + 30)/3 = 27
P.V.S. Lakshmi Jagadamba
P2 , P3 , P1
The
Gantt
chart
P2
for
P3
the
schedule
P1
30
Process Management
(3 + 6 + 30)/3 = 13
is:
This problem results in lower CPU and device utilization; Case #2 shows
that higher utilization might be possible if the short processes were
Once the CPU has been allocated to a process, that process keeps the
CPU until it releases it either by terminating or by requesting I/O
Process Management
Selection function: the process that has been waiting the longest in
Process Management
FCFS drawbacks
Process Management
Process Management
The SJF algorithm associates with each process the length of its next CPU burst
When the CPU becomes available, it is assigned to the process that has the smallest
next CPU burst (in the case of matching bursts, FCFS is used)
SJF is optimal gives minimum average waiting time for a given set of processes
Two schemes:
Preemptive if a new process arrives with a CPU burst length less than the
remaining time of the current executing process, preempt. This scheme is know as
the Shortest-Remaining-Time-Next (SRTN)
Process Management
Burst Time
P1
0.0
P2
0.0
P3
0.0
P4
0.0
P3
0 1
P2
P4
5
P1
10
16
Process Management
Burst Time
P1
0.0
P2
2.0
P3
4.0
P4
5.0
P1
P3
P2
0
3
7
8
12
Average waiting time
= ( (0 0) + (8 2) + (7 4) + (12 5) )/4
= (0 + 6 + 3 + 7)/4 = 4
P4
16
Burst Time
P1
0.0
P2
2.0
P3
4.0
P4
5.0
P1
P2
P3
P2
P4
P1
16
0
11
2
4
5
7
Average waiting time
= ( [(0 0) + (11 - 2)] + [(2 2) + (5 4)] + (4 - 4) + (7 5) )/4
= 9 + 1 + 0 + 2)/4
=3
Average turn-around time = (16 + 7 + 5 + 11)/4 = 9.75
Waiting time : sum of time that a process has spent waiting in the ready queue
Process Management
Priority Scheduling
Process Management
Priority Scheduling
The SJF algorithm is a special case of the general priority scheduling algorithm
The CPU is allocated to the process with the highest priority (smallest integer = highest
priority)
A preemptive approach will preempt the CPU if the priority of the newly-arrived
process is higher than the priority of the currently running process
A non-preemptive approach will simply put the new process (with the highest
priority) at the head of the ready queue
SJF is a priority scheduling algorithm where priority is the predicted next CPU burst
time
The main problem with priority scheduling is starvation, that is, low priority processes
may never execute
A solution is aging; as time progresses, the priority of a process in the ready queue is
increased
Process Management
Priority
P1
10
P2
P3
P4
P5
P1
P5
P2
1
P3
16
P4
18
19
Process Management
q large FIFO
Process Management
Burst Time
P1
53
P2
P3
17
68
P4
24
The Gantt chart is:
P1
0
20
P2
37
P3
57
P4
P1
77
P3
97
117
P4
P1
P3
P3
Typically, higher average turnaround than SJF, but better response time
Average waiting time
= ( [(0 0) + (77 - 20) + (121 97)] + (20 0) + [(37 0) + (97 - 57) + (134 117)]
+ [(57 0) + (117 77)] ) / 4
= (0 + 57 + 24) + 20 + (37 + 40 + 17) + (57 + 40) ) / 4
= (81 + 20 + 94 + 97)/4
= 292 / 4 = 73
Arrival
Time
1
2
3
4
0
1
2
3
Note:
Example violates rules for quantum
size since most processes dont
finish in one quantum.
Service
Time
8
4
9
5
P2
P3
P4
12
P1
16
P3
20
P4
24
P3
25
Process Management
26
Process Management
Process Management
Process Management
Multi-level queue scheduling is used when processes can be classified into groups
The two types of processes have different response-time requirements and so may have
different scheduling needs
Also, foreground processes may have priority (externally defined) over background processes
A multi-level queue scheduling algorithm partitions the ready queue into several separate queues
The processes are permanently assigned to one queue, generally based on some property of the
process such as memory size, process priority, or process type
In addition, there needs to be scheduling among the queues, which is commonly implemented as
fixed-priority pre-emptive scheduling
The foreground queue may have absolute priority over the background queue
Process Management
One example of a multi-level queue are the five queues shown below
For example, no process in the batch queue can run unless the queues above it are empty
However, this can result in starvation for the processes in the lower priority queues
Process Management
Each queue gets a certain portion of the CPU time, which it can then schedule among
its various processes
The foreground queue can be given 80% of the CPU time for RR scheduling
The background queue can be given 20% of the CPU time for FCFS scheduling
Process Management
Process Management
parameters:
number of queues
Process Management
Three queues:
Q2 FCFS
Scheduling
Process Management
Guaranteed Scheduling
Process Management
Guaranteed Scheduling
To achieve guaranteed 1/n of cpu time (for n
processes/users logged on):
0
0
1
Process 1
0
0
0
1
Process 2
0
0
Process 3
0
0
1
0
1
0
1
Process 1
Process 2
Process 3
1
1/ 3
0
1/ 3
0
1/ 3
2
0
1
0
1
Process 1
Process 2
Process 3
1
2/3
1
2/3
0
2/3
3
0
1
0
1
Process 1
Process 2
Process 3
1
3/3
1
3/3
1
3/3
4
0
1
0
1
Process 1
Process 2
Process 3
2
4/3
1
4/3
1
4/3
5
0
1
0
1
Process 1
Process 3
2
5/3
2
5/3
6
0
1
0
1
Process 1
Process 2
Process 3
3
6/3
1
6/3
2
6/3
7
0
1
0
1
Process 1
Process 2
Process 3
3
7/3
2
7/3
2
7/3
8
0
1
0
1
Process 1
Process 2
Process 3
3
8/3
3
8/3
2
8/3
9
0
1
0
1
Process 1
Process 2
Process 3
3
9/3
3
9/3
3
9/3
Process Management
Process Management
Process Management
Process Management
Deadline Scheduling
Deadline scheduling
Difficult to implement
Must
Incurs
significant overhead
Service
Process Management
Real-Time Scheduling
Real-time scheduling
Two categories
For
Failure
For
Process Management
Real-Time Scheduling
Static real-time scheduling
Low overhead
real-time schedulers
Deadline RM scheduling
Useful
period
Process Management
Real-Time Scheduling
Dynamic real-time scheduling
Can incur significant overhead, but must ensure that the overhead
does not result in increased missed deadlines
(EDF)
Minimum-laxity-first
Process Management
User-level threads
Implemented
Operating
Kernel-level threads
Implemented
at kernel level
Scheduler
Process Management
Threads
Process Management
Process Management
requirements.
Within a computer system, we need policies to schedule access
Process Management
parameters:
Processor utilization
Fairness of allocation
We see that measures for response time and turn around are
Process Management
Process Management
Comparison of Policies
Let us consider 5 processes P1 through P5.
Assumptions:
Process Management
Process Management
Summary of Results
Case B : Average time to complete - 50 (case of FCFS)
Process Management
Preemptive Policies - 1
Process Management
Summary of Results
In the figure, we compare four cases:
Clearly it would seem that shortest job first is the best policy. In fact
End of Chapter 3
Process Management