Title: Operating Systems: Introduction
1Operating Systems Introduction
- 1. Historical Development
- 2. The OS as a Resource Manager
- 3. Definitions
- 4. The Process
2The OS as a Resource Manager
- Resources
- 4 functions
- Keep track of resource
- Enforce policy -
- Allocate
- Reclaim
3The OS as a Resource Manager
- Memory management
- Keep track
- If multiprogramming
- Allocate
- Reclaim (pi relinquishes it or terminates)
4The OS as a Resource Manager
- Processor management
- Keep track of
- Scheduling
- Allocate
- Reclaim pi relinquishes P, terminates, exceeds
TS
5The OS as a Resource Manager
- Device management
- Keep track of devices, channels, control units
- Efficient allocation policy
- Allocate
- Reclaim Normally automatic termination
6The OS as a Resource Manager
- Information management
- Keep track Location, use, status ( )
- Who gets use of resources, enforce protection,
provide accessing routines - Allocate (Open file)
- Deallocate (Close file)
7Processor management lower module (P,V), Process
Scheduler
Level 5
Kernel
Level 4
Level 3
Memory management
Level 2
Level 1
Processor management upper module (messages,
create-destroy process)
Bare machine
Device management (I/O traffic control)
Info management (File system)
8Supervisor process (Job scheduler)
Jobs
Hierarchical OS Structure
Process 1
Process 2
SPOOLing
Process 3
User-created process
I/O process
I/O process working with User process 3
Layer 1
Layer 2
Kernel (Layer 0)
9Definitions
- Operating System (OS)
- Software governing control of resources
- (
) - Interface
- Processor Hardware which interprets and
executes instructions - Process (task)
- Job Set of modules reqd to perform some task
10Definitions
- Multiprogramming
- Privileged instruction
- Instruction available only to
- Executed in supervisor (executive) state as
opposed to problem (user) state. - Interrupt
- Mechanism forcing processor to take notice of
event
11I.4 The Process
- Process (pi) A program in a state of execution
- Life (Higher level view)
- 1. Run pi
- 2. Wait For event
- 3. Ready
RUN
Wait for I/O completion
pi P
READY
WAIT
I/O complete
12Life of a Process
COMPLETE
RUN
WAIT
READY
HOLD
SUBMIT
13 Processor Management and Scheduling
- 1. Introduction
- 2. Basic Concepts
- 3. Processor Scheduling Algorithms
14 Introduction
- Given 2 jobs, A and B.
- Each executes for 1 sec, waits for 1 sec
- Repeat this for 60 cycles 2 min
- 1. Lets run A, then B
A B
2 min
2 min
Elapsed Time 4 min Compute Time 2 min CPU
Utilization 2/4 50
15 Introduction
- 2. Now multi-program A and B
A B
Elapsed Time 2 min
Compute Time 2 min
CPU Utilization 2/2 100
- Compare to 1 A finishes at same time,
- B in half the time.
16 Introduction
- So now we have multiprogramming
- N jobs in memory
- Job i P
- When i waits for I/O, j P
- Overlap CPU and I/O to keep P busy
- Benefits Increased CPU utilization and
higher throughput. - Throughput Work done in given period.
- E.g. 10 jobs per hour.
17 Basic Concepts
- Process a program in a state of execution.
- E.g. Batch job, transaction (in T-S system)
- Also called job, program, task, activity.
- Process behavior pi alternate between
execution(CPU burst) I/O(I/O burst). - Generally begins and ends with CPU bursts.
18Basic Concepts
- pi change state as they execute
- READY, RUN, WAIT, HOLD.
- Process Control Block (PCB)
- Process is represented internally by its PCB
- Active representation of passive entity, the
PGM - The only tangible part of a process
19 - PCB
- Process id
- Current State
- Priority
- Other CPU Scheduling info
- State info PC (address of NI to be executed)
register, cc contents - Memory management info base-bounds
registers, page tables - Accounting info amount of CPU time, account
- I/O status info I/O requests pending, I/O
devices allocated, list of open files - Pointer to list of all pi in same state
- etc.
20Basic Concepts
- Scheduling queues
- Ready queue List of processes (PCBs) in ready
state (awaiting assignment of P) - Device queue List of pi waiting on this device
- I/O queue pi waiting for I/O (once served, pi
moves to Ready queue).
. . .
Head Tail
PCB i
PCB j
PCB n
Registers
Registers
Registers
. . .
. . .
. . .
Queue
header
21Basic Concepts
- Schedulers
- Job (long-term) scheduler
- Selects job from spool queue to enter system,
loads it into memory - Processor (CPU, short-term) scheduler
- Selects ready pi and dispatches (assigns P to) it
22 - Difference How often they execute
- Job scheduler
- Infrequently once steady state is reached
- Controls degree of multiprogramming (number of pi
in memory) - Processor scheduler
- Must select new pi very frequently (every 10 ms)
- FAST or much of the processor time is spent in
scheduling !
23Basic Concepts
- Dispatcher
- Assigns P to pi selected by Processor scheduler
- Loads pis registers
- Changes to user mode
- Jumps to proper address to (re)start it
24 Processor Scheduling Algorithms
- Problem Which pi in Ready queue gets P?
- Performance Criteria (Comparing algorithms)
- Throughput Work done in given period.
- CPU utilization P busy time / Total elapsed
time - Want it as busy as possible (40-90).
- Turnaround time Interval between submission to
completion of job (Batch OS). - Wait time Time spent by pi in Ready queue.
- Response time Interval from submission until
response produced (Interactive system).
25Processor Scheduling Algorithms
- Lets optimize as follows
- Maximize CPU utilization, throughput
- Minimize turnaround time (TT), wait, response
time. - Operationally
- Optimize average or max or min
- e.g. Minimize the max response time Minimize
variance in response time.
26Common Scheduling Algorithms
- (a) First Come First Served (FCFS)
- (b) Shortest Job First (SJF)
- (c) Priority
- Preemptive vs Non-preemptive
- (d) Round Robin
- (e) Multilevel Queues
27Scheduling Algorithms
- First Come First Served (FCFS)
- Implementation FIFO queue
- pj enters ready q
- pi dispatched
- Consider Job CPU burst A 24
B 3 C 3
pi
pk
pj
...
RQ
pk
pj
...
RQ
28 - FCFS
- Suppose jobs arrive in order A, B, C and are
served FCFS. - TT For A 24, For B 27, For C 30
- Avg TT (24 27 30) / 3 27
- Now, suppose they arrive in order B, C, A
- Avg TT (3 6 30) / 3 13
A
B
C
24
27
30
0
A
B
C
30
6
3
0
29Scheduling Algorithms
- Shortest Job First (SJF)
- Associates with job the length of its next CPU
burst - Example of priority scheduling (job with shortest
next CPU burst gets highest priority) - Consider Job CPU burst A
6 B 3 C 8 D
7
30 - SJF
- Avg TT (3 9 16 24) / 4 13
- This algorithm can be proved optimal
- Gives min avg wait time for given set of jobs
- Problem Length of next CPU burst
- Batch jobs Time limit supplied by user
- Processes Cant know but can predict
B3
D7
C8
A6
0
3
9
16
24
31Scheduling Algorithms
- Priority Scheduling
- Can be assigned who is paying, type of work
- Can be computed
- Time limits, memory req., ratio avg I/O burst to
CPU burst, number of open files - Major problem Starvation
- Low priority Ready pi can wait indefinitely for
CPU - Eventually, load lightens and job gets run, or
system crashes and job is lost - Remedy
- Aging Increase priority of low priority job
over time
32Scheduling algorithms
- Round Robin (RR)
- Designed for TS systems
- Given defined TS (10-100 ms).
- CPU scheduler traverses Ready queue, selects pi
to be dispatched for interval ? TS - Implementation
- Ready queue FIFO queue
- CPU scheduler picks 1st job in Ready queue
- Sets timer to interrupt after 1 TS
- Dispatches process
33 Scheduling algorithms
- Multilevel Queue
- Good when jobs easily classified into groups
- e.g. foreground (FG - interactive)
and background (BG - batch) - In a multilevel scheduling algorithm
- Ready queue partitioned into separate queues
- Each pi assigned permanently to one queue
- Due to memory size, job type,
- Each queue has its own scheduling algorithm
- FG RR, BG FCFS
- Must have scheduling between the queues
- e.g. Fixed priority preemptive (such as FG BG)