Você está na página 1de 36

Understanding OS Processes

Evolution of OS

Serial Processing
Simple Batch System
Multiprogrammed Batch
Systems
Multitasking/Time
Sharing

Process

Design

Monolithic
Layered systems
Microkernel

Process Control Block


Role of Dispatcher
2-state process model

Creation/Termination
5-state process model

New, Ready, Run,

Blocked/Waiting, Exit

Trace and dispatcher

Queuing model
Suspended Process

Need for Swapping

Concept of Mechanisms
(what/how to do?) And
Policies (which?)
Process treats an OS as a
set of APIs
CPU Virtualization an
illusion by the OS

6/7-state process model

Few other concepts

Process preemption

Process/Context
switching kernel, trap
tables

System/User level

CPU / I/O-bound

Cooperative / NC

OS Ctrl structures

OS Ctrl Tables

Process Ctrl Structures

Elements of Process Image


PCB
Process List Structures

PCB List based on states


Process Control

Modes of Execution

Protect sys. structures

Steps - Process Creation

Process Switching

Role of schedulers

Types of schedulers

Mix of CPU and I/O


bound jobs

New job
Interactive logon
Created for OS service
Spawn by existing process

Process

Evolution of OS

Serial Processing
Simple Batch System
Multiprogrammed Batch
Systems
Multitasking/Time
Sharing

Design

Monolithic
Layered systems
Microkernel

Process Control Block


Role of Dispatcher
2-state process model

Creation/Termination
5-state process model

New, Ready, Run,

Blocked/Waiting, Exit

Trace and dispatcher

Queuing model
Suspended Process

Need for Swapping

6/7-state process model

Few other concepts

Process preemption

Process/Context
switching

System/User level

CPU / I/O-bound

Cooperative

OS Ctrl structures

OS Ctrl Tables

Process Ctrl Structures

Elements of Process Image


PCB
Process List Structures

PCB List based on states


Process Control

Modes of Execution

Protect sys. structures

Steps - Process Creation

Process Switching

Role of schedulers

Types of schedulers

Mix of CPU and I/O


bound jobs

Process

Evolution of OS

Serial Processing
Simple Batch System
Multiprogrammed Batch
Systems
Multitasking/Time
Sharing

Design

Monolithic
Layered systems
Microkernel

Process Control Block


Role of Dispatcher
2-state process model

Creation/Termination
5-state process model

New, Ready, Run,

Blocked/Waiting, Exit

Trace and dispatcher

Queuing model
Suspended Process

Need for Swapping

6/7-state process model

Few other concepts

Process preemption

Process/Context
switching

System/User level

CPU / I/O-bound

Cooperative

Normal completion
Time limit exceeded
Mem unavailable
Protection error
Arithmetic error
Time overrun (wait)
I/O failure
Privileged instruction
OS intervention

OSParent
Ctrltermination
structures

OSParent
Ctrl Tables
request

Process Ctrl Structures

Elements of Process Image


PCB
Process List Structures

PCB List based on states


Process Control

Modes of Execution

Protect sys. structures

Steps - Process Creation

Process Switching

Role of schedulers

Types of schedulers

Mix of CPU and I/O


bound jobs

Process
Can affect the execution

Evolution of OS

Serial Processing
Simple Batch System
Multiprogrammed Batch
Systems
Multitasking/Time
Sharing

Design

Monolithic
Layered systems
Microkernel

Process
Block
of otherControl
processes
Role of Dispatcher
Can be
affectedmodel
by
2-state
process

other processes
Creation/Termination
5-state process model
Share data with

New,
Ready, Run,
other
processes

Blocked/Waiting, Exit

Trace and dispatcher

Queuing model
Suspended Process

Need for Swapping

6/7-state process model

Few other concepts

Process preemption

Process/Context
switching

System/User level

CPU / I/O-bound

Cooperative

OS Ctrl structures

OS Ctrl Tables

Process Ctrl Structures

Elements of Process Image


PCB
Process List Structures

PCB List based on states


Process Control

Modes of Execution

Protect sys. structures

Steps - Process Creation

Process Switching

Role of schedulers

Types of schedulers

Mix of CPU and I/O


bound jobs

Process

Process Control Block

Role of Dispatcher
stack etc.
User Data program data, user
2-state process model

User Program Program to be executed


Creation/Termination
Evolution
of
OS
Stack call parameters, addresses

5-state process model

Serial
Processing
PCB Data needed by OS to control

New, Ready, Run,

Simple
Batch
System
the process

Blocked/Waiting, Exit

Multiprogrammed Batch

Trace and dispatcher


Systems

Queuing model

Multitasking/Time

Suspended Process
Sharing

Need for Swapping

Design

Monolithic
Layered systems
Microkernel

6/7-state process model

Few other concepts

Process preemption

Process/Context
switching

System/User level

CPU / I/O-bound

Cooperative

OS Ctrl structures

OS Ctrl Tables

Process Ctrl Structures

Elements of Process Image


PCB
Process List Structures

PCB List based on states


Process Control

Modes of Execution

Protect sys. structures

Steps - Process Creation

Process Switching

Role of schedulers

Types of schedulers

Mix of CPU and I/O


bound jobs

Process

PCB

Process Identification
Evolution
of
OS
(pid, ppid, uid)

Serial Processing

Simple Batch
Processor
StateSystem
Info.

Multiprogrammed
Batch
(user-visible
registers,
Systems registers,
Control/Status

Multitasking/Time
Stack pointers)
Sharing

Process Control Info.


(scheduling and state info.,

Design
Process
data structuring,

Monolithic comm.,
Inter-process

Layered
Process privileges,
systems

Memory mgmt.,
Microkernel
Resource ownership
And utilization)

Process Control Block


Role of Dispatcher
2-state process model

Creation/Termination
5-state process model

New, Ready, Run,

Blocked/Waiting, Exit

Trace and dispatcher

Queuing model
Suspended Process

Need for Swapping

6/7-state process model

Few other concepts

Process preemption

Process/Context
switching

System/User level

CPU / I/O-bound

Cooperative

OS Ctrl structures

OS Ctrl Tables

Process Ctrl Structures

Elements of Process Image


PCB
Process List Structures

PCB List based on states


Process Control

Modes of Execution

Protect sys. structures

Steps - Process Creation

Process Switching

Role of schedulers

Types of schedulers

Mix of CPU and I/O


bound jobs

Process

Evolution of OS

Serial Processing
Simple Batch System
Multiprogrammed Batch
Systems
Multitasking/Time
Sharing

Design

Monolithic
Layered systems
Microkernel

Process Control Block


Role of Dispatcher
2-state process model

Creation/Termination
5-state process model

New, Ready, Run,

Blocked/Waiting, Exit

Trace and dispatcher

Queuing model
Suspended Process

Need for Swapping

OS Ctrl structures

Process Ctrl Structures

6/7-state process model

Few other concepts

Process preemption

Process/Context
switching
Assign a unique pid

System/User
Allocate
space for thelevel
process

CPU
/ I/O-bound
Initialize
the PCB

Cooperative
Set the
appropriate linkages

OS Ctrl Tables

Create/expand system data structures

Elements of Process Image


PCB
Process List Structures

PCB List based on states


Process Control

Modes of Execution

Protect sys. structures

Steps - Process Creation

Process Switching

Role of schedulers

Types of schedulers

Mix of CPU and I/O


bound jobs

With Suspend State

7-State Process Model

Ready: Process is in Main Memory and ready for execution.


Blocked: Process is in Main Memory and awaiting an event I/O.
Blocked, Suspended: Process is in Secondary Memory and awaiting an event I/O.
Ready, Suspended: Process is in Secondary memory and available for execution as soon as
loaded in main memory

Process state-based Queuing Models

Process state-based Queuing Models

Process / CPU Scheduling Policies

Scheduling Goals
Scheduling Goals

Performance

Throughput

Response Time

Throughput - Rate at which useful work is accomplished, e.g, search transaction on Google.
Many context switch not good for high throughput,
but may be necessary for quick response time.
Remember: It is not only CPU, efficient
use of I/O, memory efficiently, a
scheduler can maximize throughput.

Scheduling Mechanism
Non-preemptive vs. Preemptive

Process Parameters for Scheduling


Arrival Time (AT)
Service Time (ST) / Execution Time (ET) /
Burst Time (BT)
Priority Static vs. Dynamic (No., reverse)
Finish Time (FT)
Turnaround time (TAT) and Mean TAT
Waiting Time (WT) and Mean WT

Exact Schedule (run order) of processes

Visualization

Uniprocessor
Scheduling
Focus:
State
of
Ready
Queue
Policy dependent

Gantt Charts (or Time scale diagram)

Process / CPU Scheduling Policies


First Come First Serve (FCFS) / First In First Out (FIFO)
Shortest Process Next (SPN) / Shortest Job First (SJF)
Highest Response Ratio Next (HRRN)
Priority-based
Round Robin (RR)
Shortest Remaining Time Next (SRTN) / Preemptive Shortest Process Next
(P-SPN)
Multi-level Queue (MLQ)
Multi-level Feedback Queue (MLFQ) (sometimes called Feedback scheduling)

Multi-level Queue (MLQ) Scheduling

Multiple queues, No feedback

Every queue can have a separate scheduling function

3 queues : RR (q=2), RR(q=3), RR(q=5)

3 queues : FCFS, SPN, SRTN (possible ordering: SPN, SRTN, FCFS).

It is important to consider the queue ordering.

Unless the first queue is empty, the next queue will not be considered in
scheduling other processes.

In case of 3 queues, queue 2 not processed until queue 1 gets empty, queue 3
not processed until queues 1 and 2 get empty.

It is possible to place a process in one or more queues depending on the


criteria (for e.g., execution time, memory usage, ratio of CPU and I/O usage) to
assign a queue. However, there should be a policy to resolve any such conflict.

For e.g., FCFS (t > 10), SPN(t < 5), SRTN(5 < t < 10)
In case different queue ordering is considered, it is possible to reach to
different schedules suggesting multiple ways to schedule a given set of
processes.
Scheduler scans all queues based on queue ordering.

Example 1 : Schedule Processes


FCFS,
RR (q=1), RR(q=4),
SPN/SJF,
Priority-based
SRT/SRTN,
Process priority

HRRN,

A (3), B(1), C(0), D(1), E(2)

Multi-level Queue
(q=1,2,3)
Feedback (q=1), (q=2^n)

Solution Example 1: Schedule of Processes

Example 2

Example 3
FCFS,
RR (q=1),
RR(q=4),
SPN/SJF,
SRT/SRTN,
HRRN,
Multi-level Feedback (q=2),
Multi-level Feedback (RR=1,SRT, HRRN)

Remember:
For HRRN (is preemptive when time quantum is given) when used in MLFQ scheduling
Response Ratio = (WT + RST) / RST,
where WT indicates waiting time w.r.to arrival time, and
RST indicates remaining service time based on status of a process in a particular queue.
RST = Total service time time for which CPU has already been assigned to that process.
When policies like SJF, SRT, HRRN are used in context of feedback scheduling, each of
these policies are only used for process selection from the queue. However, CPU time is
given only for a given/assumed time slot, and then the process is moved to next queue if it is
not yet completed.

Example 4

b) Draw a chart showing execution of processes using SRTN. For each process, calculate the
total time spent in the Ready queue.
c) Draw a chart showing execution of processes using HRRN.
d) Draw charts for the MLFQ (4 queues, q=2n+1, n=0,1,2,3)

Example 5

Example 6

FCFS
RR(q=1,2,4)
SPN(Shortest Process Next, Non-preemptive)
SRTN (a.k.a. PSPN(Shortest Process Next, preemptive))
HRRN
Preemptive HRRN
MLFQ (q=2n+1, n={0,0.5,1,1.5})

Solution 6

Solution 6 ...cont'd

Solution 6...cont'd
RR (q = 1)

Example 7

(a) The system uses RR scheduling with q=10 ms and q=5 ms.
(b) The system uses MLFQ scheduling with 4 queues, q=2n-1, where n=1,2,3,4

Solution 7 (a)
Time

CPU Use

Ready Queue
(end of time slot)

I/O Use

Blocked (I/O) Queue

Example 8
Consider the following three processes. Each process makes a CPU burst
then an I/O burst, another CPU burst, another I/O burst and terminates
with a CPU burst. The lengths of the CPU burst and I/O burst times in
milliseconds are given in the following table:
Process

CPU-burst1

I/O-burst1 CPU-burst2

I/O-burst2 CPU-burst3

Arrival

P1

P2

P3

The processes are assumed to arrive as indicated.


Draw charts that illustrate the execution of theses processes using the (1)
FCFS (2) RR (q = 1) (3) RR ( q = 2) (4) SJF (5) HRRN (6) SRTN (7)
MLFQ (4 queues, q=2k, k=1,1.5,2,2.5).
Clearly indicate the queue state, and use the charts to compute FT,WT and
its WT, TAT and its mean. Give your conclusion about the comparative
performance of the above listed policies.
If an I/O completion and a CPU timeout of two processes occur at the same
time, we treat the I/O completion first.

Soluiton 8

Solution 8 ... cont'd

Solution 8 ... cont'd

Example 9

(typical objective type questions)

CPU Scheduling Algorithms

Você também pode gostar