Documente Academic
Documente Profesional
Documente Cultură
(AOS)
BEIT-V SEMESTER
Compiled By
Asst. Prof. Madan Kadariya
HOD, Department of Information Technology
Engineering
Nepal College of Information Technology
Balkumari Lalitpur
CHAPTER 2
PROCESS/THREAD MANAGEMENT
3
SCHEDULING
Basis of multiprogrammed OS
The run of a process: CPU Burst
6
DISPATCHER
Dispatcher module gives control of the CPU to the process
selected by the short-term scheduler; this involves:
switching context
switching to user mode
7
SCHEDULING CRITERIA
CPU Utilization:
Average time during which CPU is busy executing user programs and/or
system programs.
The more the better
Response Time:
Amount of time it takes from when a request was submitted
until the first response is produced, not output (for time-
sharing environment)
Minimum is better.
9
OPTIMIZATION CRITERIA
Max CPU utilization
Max throughput
10
SCHEDULING ALGORITHMS GOALS
All Systems:
Fairness:
Fair share of CPU to every process
Policy Enforcement:
12
ALGORITHMS USED IN DIFFERENT
SYSTEMS
First-Come-First-Serve (FCFS)
Shortest Job First (SJF)
13
SCHEDULING ALGORITHMS (TYPES)
Non-Preemptive Algorithm Preemptive Algorithm
Once the CPU is allocated to a CPU can be taken away before the
process, it cannot be taken away from completion
P1 P2 P3
0 24 27 30
17
SHORTEST JOB FIRST (SJF)
Allocate the CPU to the process with least CPU burst
time
If two processes have same CPU burst, then FCFS is
P1 P3 P2 P4
0 3 7 8 12 16
0 2 4 5 7 11 16
20
Average waiting time = (9 + 1 + 0 +2)/4 = 3
SJF
Advantages:
Optimal gives minimum average waiting time for a given
21
QUESTION:
Make Gantt Chart and Find:
Average Turnaround Time (ATAT)
Average Waiting Time (AWT)
Case1: FCFS
P0 0 10
P1 1 6
P2 3 2
22
P3 5 4
PRIORITY SCHEDULING
Gives preferential treatment to important jobs.
Allows the programs with the highest priority to be
processed first
FCFS algorithm
The priority determination is affected by:
Resource requirement
Processing time
Total spent time on the system
23
PRIORITY SCHEDULING
Types:
PreemptivePriority Scheduling
24
PRIORITY SCHEDULING
A priority number (integer) is associated with each process
The CPU is allocated to the process with the highest priority
(smallest integer)
27
NON-PREEMPTIVE PRIORITY
Example:
Process Arrival Burst Time Priority
Time (AT)
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
33
MULTILEVEL QUEUE SCHEDULING
Ready queue is partitioned into separate queues:
foreground(interactive)
background (batch)
foreground RR
background FCFS
Scheduling must be done between the queues.
Fixedpriority scheduling; (i.e., serve all from foreground then from
background). Possibility of starvation.
Time slice each queue gets a certain amount of CPU time which it can
schedule amongst its processes; i.e., 80% to foreground in RR; 20% to
background in FCFS
34
Applied Operating System (AOS)
35
MULTILEVEL QUEUE SCHEDULING
MULTILEVEL FEEDBACK QUEUE
A process can move between the various queues
aging can be implemented this way
Multilevel-feedback-queue scheduler defined by the
37
Applied Operating System (AOS)
38
MULTILEVEL FEEDBACK QUEUES
THREAD SCHEDULING
User-level threads and Kernel-level threads
All the scheduling algorithms in thread supporting OS are
Kernel-level scheduling not processes
39
THREAD SCHEDULING
User Level Thread Kernel Level Thread
Possible: A1, A2, A3, A1, A2, A3 Possible: A1, A2, A3, A1, A2, A3
Not-Possible: A1, B1, A2, B2, A3, B3 Also Possible: A1, B1, A2, B2, A3, B3
40
Q. Consider the following set of processes, with the length of the CPU burst given in
milliseconds:
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 3
42
Process Scheduling Example
0 5 10 15 20
A
First-Come-First B
Served (FCFS) C
D
E
A
Round-Robin B
(RR), q =1 C
D
E
A
Round-Robin B
(RR), q =4 C
A
Shortest Process B
Next (SPN) C
D
E
A
Shortest Remaining B
Time(SRT) C
D
E
A
Highest Response B
Ratio Next (HRRN) C
D
E
A
Feedback B
q =1 C
D
E
A
Feedback B
i
q =2 C
D
43
E
0 5 10 15 20
Figure 9.5 A Comparison of Scheduling Policies
SUMMARY
CPU scheduling is the task of selecting a waiting process from
the ready queue and allocating the CPU to it.
The CPU is allocated to the selected process by the dispatcher.