OS_slot_7-8_chap2_scheduling_IPCproblems
OS_slot_7-8_chap2_scheduling_IPCproblems
2.1 Processes
2.2 Threads
2.3 Interprocess communication
2.4 Scheduling
2.5 Classic Interprocess Communication Problems
2.4 Scheduling
2
Scheduling
Introduction to Scheduling (1)
3
Scheduling
Introduction to Scheduling (2)
4
Scheduling
Introduction to Scheduling (3)
• Selects from among the processes in memory that are ready to execute,
and allocates the CPU to one of them
• CPU scheduling decisions may take place when a process:
1. Switches from running to waiting state
2. Switches from running to ready state
3. Switches from waiting or new process is created to ready
4. Terminates
• Non-preemptive scheduling algorithm picks process and let it run until
it blocks or until it voluntarily releases the CPU
• preemptive scheduling algorithm picks process and let it run for a
maximum of fix time
6
Scheduling
Introduction to Scheduling (5)
ready running
interrupt
I/O or
I/O or event event wait
completion
waiting
7
Scheduling
Introduction to Scheduling (6)
Scheduling Criteria
• CPU utilization – keep the CPU as busy as possible
• Throughput – the number of processes that complete their
execution per time unit
• Turnaround time – amount of time to execute a particular process
from the arrival moment
• Waiting time – amount of time a process has been waiting in the
ready queue
• 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)
8
Scheduling
Introduction to Scheduling (7)
Optimization Criteria
• Max CPU utilization
• Max throughput
• Min turnaround time
• Min waiting time
• Min response time
9
Scheduling
Introduction to Scheduling (8)
Scheduling Algorithm Goals
10
Scheduling
Scheduling in Batch Systems (1)
First-Come, First-Served (FCFS) Scheduling
Process Burst Time
P1 24
P2 3
P3 3
P1 P2 P3
0 24 27 30
• Waiting time for P1 = 0; P2 = 24; P3 = 27
• Average waiting time: (0 + 24 + 27)/3 = 17
11
Scheduling
Scheduling in Batch Systems (2a)
FCFS Scheduling (Cont.) Process Burst Time
Suppose that the processes arrive in the order P1 24
P2 , P3 , P1 P2 3
P3 3
• The Gantt chart for the schedule is:
P2 P3 P1
0 3 6 30
Arrival time 4 1 0 2
Process ID P1 P2 P3 P4
CPU burst time 5 2 6 4
13
Scheduling
Scheduling in Batch Systems (3)
14
Scheduling
Scheduling in Batch Systems (4)
15
Scheduling
Scheduling in Batch Systems (5)
Process ID P1 P2 P3 P4
CPU burst time 5 2 6 4
Arrival time 0 1 2 3
16
Last lesson
• Scheduling criteria:
CPU utilization, throughput, turnaround time, waiting time, response time
Maximum Minimum
Last lesson
• Schemes of scheduling algorithms:
Non-preemtive scheme preemtive scheme
I want to use
I want to use
this computer
this computer
Last lesson
• Scheduling algorithms:
– First Come First Served
– Shortest-Job First
Scheduling
Scheduling in Interactive Systems (1)
20
Scheduling
Scheduling in Interactive Systems (2)
21
Scheduling
Scheduling in Interactive Systems (3a)
P1 P2 P3 P1 P3 P3
0 20 37 57 60 80 85
22
Scheduling
Scheduling in Interactive Systems (3b)
23
Scheduling
Scheduling in Interactive Systems (4)
Priority Scheduling: A priority number (integer) is associated with each
process
– The CPU is allocated to the process with the highest priority
– Preemptive
– nonpreemptive
• SJF is a priority scheduling where priority is the predicted next CPU burst time
• Problem ≡ Starvation – low priority processes may never execute
• Solution ≡ Aging – as time progresses increase the priority of the process
24
Scheduling
Scheduling in Interactive Systems (5)
A scheduling algorithm with four priority classes
25
Scheduling
Scheduling in Interactive Systems (5a)
Example of priority scheduling algorithm
P2 P5 P1 P3 P4
0 2 7 14 15 17
26
Scheduling
Scheduling in Interactive Systems (5b)
Example of priority scheduling algorithm
27
Scheduling
Scheduling in Real-Time Systems (1)
28
Scheduling
Scheduling in Real-Time Systems(2)
29
Scheduling
Scheduling in Real-Time Systems (3)
30
Scheduling
Policy versus Mechanism
31
Scheduling
Thread Scheduling (1)
32
Scheduling
Thread Scheduling (2)
34
2.5 Classic Interprocess
Communication Problems
35
Classic interprocess communication problems