0% found this document useful (0 votes)
3 views36 pages

OS_slot_7-8_chap2_scheduling_IPCproblems

The document provides an overview of scheduling in operating systems, detailing various scheduling algorithms such as First-Come, First-Served, Shortest-Job-First, Round Robin, and Priority Scheduling. It discusses the criteria for evaluating scheduling performance, including CPU utilization, throughput, turnaround time, waiting time, and response time. Additionally, it addresses scheduling in different contexts, including batch systems, interactive systems, and real-time systems, along with classic interprocess communication problems.

Uploaded by

d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views36 pages

OS_slot_7-8_chap2_scheduling_IPCproblems

The document provides an overview of scheduling in operating systems, detailing various scheduling algorithms such as First-Come, First-Served, Shortest-Job-First, Round Robin, and Priority Scheduling. It discusses the criteria for evaluating scheduling performance, including CPU utilization, throughput, turnaround time, waiting time, and response time. Additionally, it addresses scheduling in different contexts, including batch systems, interactive systems, and real-time systems, along with classic interprocess communication problems.

Uploaded by

d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

Overview

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)

• Maximum CPU utilization obtained with


multiprogramming
• CPU–I/O Burst Cycle – Process
execution consists of a cycle of CPU
execution and I/O wait
• CPU burst distribution

3
Scheduling
Introduction to Scheduling (2)

• Bursts of CPU usage alternate with periods of I/O wait


– a CPU-bound process
– an I/O bound process

4
Scheduling
Introduction to Scheduling (3)

Three level scheduling


5
Scheduling
Introduction to Scheduling (4)

• 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)

new admit dispatch exit terminated

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

• Suppose that the processes arrive in the order: P1 , P2 , P3


• The Gantt Chart for the schedule is:

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

• Waiting time for P1 = 6; P2 = 0; P3 = 3


• Average waiting time: (6 + 0 + 3)/3 = 3
• Much better than previous case
• Convoy effect short process behind long process
12
Scheduling
Scheduling in Batch Systems (2b)
FCFS Scheduling (Cont.)
Calculate average waiting time and average turnaround time?

turnaround time = completion time – arrival time

waiting time = completion time – arrival time – CPU burst time


= turnaround time – CPU burst time

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)

Shortest-Job-First (SJF) Scheduling


• Associate with each process the length of its next CPU burst. Use
these lengths to schedule the process with the shortest time
• Two schemes:
– Non-preemptive
– preemptive
• SJF is optimal – gives minimum average waiting time for a given set
of processes

14
Scheduling
Scheduling in Batch Systems (4)

An example of shortest job first scheduling

15
Scheduling
Scheduling in Batch Systems (5)

• Shortest-Job-First (SJF) Scheduling


– Calculate average waiting time and average turnaround time?
• Non-preemptive scheme (all processes arrive at the same time)
• Preemptive scheme

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

Sure, boss! Here you are!


You can use it after I finish I will continue after you finish

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)

• Round Robin Scheduling


– list of runnable processes (a)
– list of runnable processes after B uses up its quantum (b)

20
Scheduling
Scheduling in Interactive Systems (2)

Round Robin (RR)


• Each process gets a small unit of CPU time (time quantum), usually
10-100 milliseconds. After this time has elapsed, the process is
preempted and added to the end of the ready queue.
• If there are n processes in the ready queue and the time quantum is q,
then each process gets 1/n of the CPU time in chunks of at most q
time units at once. No process waits more than (n-1)q time units.
• Performance
– q large ⇒ FIFO
– q small ⇒ q must be large with respect to context switch, otherwise overhead is
too high

21
Scheduling
Scheduling in Interactive Systems (3a)

Example of Round Robin with Time Quantum = 20


• All processes arrive at the same time
Process Burst Time
turnaround time = completion time – arrival time
P1 23
P1 = 60; P2 = 37; P3 = 85
P2 17
P3 45 waiting time = turnaround time – burst time
P1 = 47; P2 = 20; P3 = 40
• The Gantt chart is:

P1 P2 P3 P1 P3 P3
0 20 37 57 60 80 85

Typically, higher average turnaround than SJF, but better response

22
Scheduling
Scheduling in Interactive Systems (3b)

Round Robin with Time Quantum = 4


• 5 processes are as below
Process Burst Time Arrival time
P1 5 0
P2 3 1
P3 1 3
P4 5 4
P5 6 5

• Calculate average waiting time and average turnaround time?

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

Process Burst Time Priority


P1 7 3
turnaround time = completion time – arrival time
P2 2 1
P3 1 4
waiting time = turnaround time – burst time
P4 2 5
P5 5 2

The Gantt chart is:

P2 P5 P1 P3 P4
0 2 7 14 15 17

26
Scheduling
Scheduling in Interactive Systems (5b)
Example of priority scheduling algorithm

Process Burst Time Priority Arrival time


P1 7 2 0
P2 8 0 5
P3 6 3 3
P4 10 1 14

Calculate average waiting time and average turnaround time?

27
Scheduling
Scheduling in Real-Time Systems (1)

• Hard real-time systems – required to


complete a critical task within a guaranteed
amount of time
• Soft real-time computing – requires that
critical processes receive priority over less
fortunate ones

28
Scheduling
Scheduling in Real-Time Systems(2)

Schedulable real-time system


• Given
– m periodic events
– event i occurs within period Pi and requires Ci
seconds
• Then the load can only be handled if

29
Scheduling
Scheduling in Real-Time Systems (3)

• consider a soft real-time system with three periodic events,


with periods of 100, 200, and 500 msec
• these events require 50, 30, and 100 msec of CPU time per
event, respectively
• => Schedulable?

30
Scheduling
Policy versus Mechanism

• Separate what is allowed to be done with


how it is done
– a process knows which of its children threads
are important and need priority
• Scheduling algorithm parameterized
– mechanism in the kernel
• Parameters filled in by user processes
– policy set by user process

31
Scheduling
Thread Scheduling (1)

• Local Scheduling – How the threads


library decides which thread to put onto
an available
• Global Scheduling – How the kernel
decides which kernel thread to run next

32
Scheduling
Thread Scheduling (2)

Possible scheduling of user-level threads


• 50-msec process quantum
• threads run 5 msec/CPU burst
33
Scheduling
Thread Scheduling (3)

Possible scheduling of kernel-level threads


• 50-msec process quantum
• threads run 5 msec/CPU burst

34
2.5 Classic Interprocess
Communication Problems

35
Classic interprocess communication problems

• The Dining Philoshophers Problem

• The Readers and Writers Problem

You might also like