Professional Documents
Culture Documents
Operating System Concepts
Operating System Concepts
System
Computer System
Hardware
Input
Units
CPU
Output
Units
Control
Unit
Processor
Software
Secondary
storage
Magnetic
Tapes
Cache
Memory
Compact
Disks
Application
Programs
Compilers &
Assemblers
Programming
Languages
Magnetic
Disks
Memory
RAM
Operating
System
User
ROM
Floppy
Disks
Hard
Disks
High
Level
Low
Level
Application Programs
Software
Operating System
Hardware
Application programs
Are programs produced by programming companies to help computer
users to perform useful tasks.
Input
Units
Control
Unit
Instructions
Instructions
Data
Memory
Processor
(RAM)
Output
Units
Control
Signals
Results
Cache
Memory
Data
ALU
Store Results
Results
Or
Load date
Secondary
Storage
ROM
CPU
ROM:
Cache Memory:
Processor
Cache
Memor
y
ALU
Definition:
Secondary storage units are the units used to store data
permanently.
Secondary
Storage
Magnetic Disks Magnetic Tapes
Floppy Disks
Hard Disks
Compact Disks
Magnetic Tapes:
Used to store large volume of data in large computers like
Advantages:
Compact (can store huge amount of data).
Economical (low cost).
No loss of data.
Disadvantages:
Sequential storage.
Magnetic Disks:
A surface of metal (in the case of hard disk)
or plastic (in floppy disks) coated with
magnetic material.
It rotates with a high speed.
Track
Divided into tracks and sectors.
Sector
Compact Disks:
CD/ROM (Compact Disk/Read Only Memory).
A plastic surface coated by a reflective
material.
A laser beam is used to write on CD/ROM.
Can store up to 600 Mega byte.
Batch System:
Users send their jobs to the computer operator.
Operator organize jobs into a set of batches (each contains similar
jobs).
Each batch is run separately as a set of jobs.
Next batch
Batch 1
Operator
Batch 2
CPU
Batch 1
Job
Multi-Programming System:
A number of processes are in memory inside the ready queue
waiting for the CPU (there is one user).
Windows OS using this concept.
Ready
Queue
Process 1
Process 2
Process 3
Memory
Switching between
processes
CPU
User 1
Process 1
Process 2
Process 3
User 2
Process 1
Process 2
CPU
Process 3
User 3
Process 1
Process 2
Process 3
Memory
Switching between
users processes
Multi-Processor System:
Is a system with more than one processor to maximize the system
speed.
CPU 1
User
Ready Queue
Process 1
Process 2
CPU 2
Process 3
CPU 3
Memory
Network System:
Systems that operate networks in order to achieve:
Resource sharing.
Computation speedup.
Load balancing.
Communication between hosts.
Star
Bus
Ring
Real Time
Systems
Process
Management
Memory
Hard
Process 2
Disk
Resource
Resource Types
Types
Preemptive
Resources
Non Preemptive
Resources
Ex: Memory.
Ex: CD recorder,
Because
It allows a low priority process to swapped
5kb are used for OS, 10 kb for the low priority process.
Hence, the available space is 17 kb.
A higher priority process arrives and needs 20 kb.
Swap in the high
priority process
Available
27 Kb
OS (5 kb)
High Priority
process (20
kb)
Disk
OS (5 kb)
Available
27 Kb
Available
7 Kb
OS (5 kb)
Low Priority
process (10
kb)
Available
17 Kb
High
Priority
20 Kb
Because: If a process has begun to burn a CDROM, suddenly taking the CD recorder away from
it and giving it to another process will result in a
bad CD.
Reques
t
Use
Releas
e
Process need to
be executed
(programs)
Dispatcher
Because:
When interrupt happened, OS saves the state of the current active process to
its PCB so it can continue correctly when it resumes its execution again.
To resume execution, OS reloads the process state from its PCB and continue
execution.
Passive
Programs
Disk
Open
program
Memory
Long Term
Scheduler
Select a
process
from job to
ready queue
Job (input)
Queue
Swap a
process
from ready
to job queue
Medium Term
Scheduler
Short Term
Scheduler
Process
Process
Assign the
CPU to a
process
from ready
queue
CPU
CPU
Q: Explain why?
Long term scheduler increases the degree of
multiprogramming.
Medium term scheduler decreases the degree of
multiprogramming.
Sol
:
Degree
of multi-programming is the number of
processes that are placed in the ready queue waiting for
execution by the CPU.
Process 1
Process 2
Process 3
Process 4
Process 5
Memory
Degree of
Multi-Programming
Disk
Long Term
Scheduler
Process 1
Process 2
Process 3
Process 4
Process 5
Job Queue
Memory
Degree of
Degree of
Multi-Programming
Multi-Programming
Disk
Medium Term
Scheduler
Process 1
Process 2
Process 3
Process 4
Process 5
Job Queue
Memory
Degree of
Degree of
Multi-Programming
Multi-Programming
CPU
Scheduling
((Ready
Ready Queue
Queue))
Process need to
be executed
CPU scheduling
Some Examples:
First Come First Serviced (FCFS) scheduling.
Shortest Job First (SJF) scheduling.
FCFS
Priority scheduling.
CPU Scheduling
Algorithm
Ready
Queue
SJF
Priority
Process 1
Process 2
Process 3
Memory
Dispatcher
CPU
Sol:
Preemptive scheduling: allows releasing the
Preemptive
Scheduling
CPU
Non- Preemptive
Scheduling
CPU
following parameters:
CPU utilization.
System throughput.
Turnaround time.
Waiting time.
Response time.
Sol:
CPU Utilization:
The percentage of times while CPU is busy to the
possible.
System Throughput:
The number of process that are completed per time unit
(hour)
Turnaround time:
For a particular process, it is the total time needed for
Waiting time:
The waiting time for a specific process is the sum of all
Response time.
It is the time from the submission of a process until the
It is desirable to:
Maximize:
CPU utilization.
System throughput.
Minimize:
Turnaround time.
Waiting time.
Response time.
Ready queue
FCFS Scheduling
CPU
22
33
Process
Burst Time
P1
24
P2
P3
Gant chart:
P1
P2
P3
24
27
24
27
30
+
Execution
Time
Process
Burst Time
P1
24
P2
P3
22
Gant chart:
P1
P2
P3
30
Sol:
Because:
it suffers from Convoy effect, hence, all other
18
10
18
CPU
Process
Burst Time
P1
P2
P3
P4
1. Using FCFS
Gant chart:
P1
P2
P3
P4
14
21
14
21
24
2. Using SJF
Burst Time
P1
P2
P3
P4
Gant chart:
Process
P1
P2
P3
P4
16
24
16
Burst Time
P1
30
P2
Using FCFS
P1
0
Using SJF
P2
30
32
P2
0
P1
2
32
Waiting time(P1)=0
Waiting time(P1)=2
Waiting time(P2)=30
Waiting time(P2)=0
Shortest-Remaining-Time-First (SRTF)
It is a preemptive version of the Shortest Job
First .
It allows a new process to gain the processor
if its execution time less than the remaining
time of the currently processing one.
SRTF Scheduling
2
10
3
4
CPU
Burst Time
Arrival Time
P2
P3
P4
1. Using SJF
Gant chart:
P1
P2
P3
P4
10
11
2. Using SRTF
Burst Time
Arrival Time
P1
P2
P3
P4
Gant chart:
Process
P1
P2
P3
P4
16
Priority scheduling
A priority number (integer) is associated
with each process
The CPU is allocated to the process with the
highest priority (smallest integer). There are
two types:
Preemptive
nonpreemptive
Priority Scheduling
10
18
10
18
CPU
26
28
Starvation
Aging
30
8
Burst Time
priority
P1
10
P2
P3
P4
P5
Process
P1
P2
P3
P4
P5
16
18
16
18
19
CPU
RR with Q=4
Process
Burst Time
P1
24
P2
P3
Gant chart:
P1
P2
P3
30
10
RR with Q=2
Process
Burst Time
P1
24
P2
P3
Gant chart:
P1
P2
P3
30
10
queues.
With feedback: processes can move between queues.
Each queue has specific priority and its own scheduling algorithm (FCFS, ).
High priority Queue
Queue 0
Queue 1
Queue 2
Deadlock
Deadlock:
Resource
Process A
Deadlock
Give me your
recourse first
Process B
Resource
Hence, blocked processes will never change state (Explain why?) because the
resource it has requested is held by another waiting process.
Deadlock
System Breakdown
Deadlock conditions
Mutual
Exclusion
Circular
wait
Hold and
wait
No preemption
11
Mutual
Exclusion
No Preemption
33
A resource is released only by the
process holding it after it completed
its task
44
44
Circular Wait
Circular
wait
There exists a set {P0, P1, P2, .., Pn} of waiting processes such that:
P0 waiting for a resource held by P1.
P1 waiting for a resource held by P2.
P2 waiting for a resource held by P3.
P0
Pn
P1
Circular
Wait
P2
P3
P4
Deadlock Modeling
(Resource Allocation Graph)
In order to solve the deadlock problem, we must find a method to
express it.
This can be achieved using resource allocation graph.
it is a graph expressing:
- All system active processes.
- Available system resources .
- Interconnections between active processes and system resources.
Process
Resource
Edge
Pi
Rj
( Request edge )
Process Pi requests an instance of
resource Rj
Rj
( Assignment edge )
An instance of Resource Rj is
assigned to Process Pi
Pi
Example:
11
Resource instances:
One instance of R1 and R3.
Two instances of R2.
ThreeP,
instances
R4.
The sets
R, andofE:
22
Processes States:
P =Process
Waiting
{ P1, P2, P3Holding
}
of R2
Instance of R1
R = {P1R1, RInstance
2, R3, R4 }
Instance of R1 and R2
Instance of R3
E = {P2
P1R1, P2R3, R1P2, R2P2,
Instance of R3
------R PP3,R P }
2
Q: Explain why: Although the graph contains a cycle, the system may
not in a deadlock state.
Sol:
Case 1: The system has one instance per resource type
R2
Cycle
Cycle:
Cycle
R1
P1 R1 P2 R2
(Deadlock)
P2
Case 2: The system has more than one instance per resource type
P2 R3 P3 R2
Cycle:
Cycle
P1 R1 P3 R2
Deadlock Avoidance
Q: Describe in details the basic rules used for deadlock avoidance .
Sol:
Examines the system state so that:
System state
Safe
No deadlock
Unsafe
Possibility of deadlock
Can be executed by
Can be executed by
11 it holds
resources
+
22
systems
available resources.
11
resources it holds
+
systems22
available resources.
+
Resources 3held
by P1
3
11
resources it holds
+
systems22
available resources.
+
Resources 3held
by P1, P2
3
Avoidance Algorithms
Resource Allocation Graph Algorithm
22
Assignment
Edge
Request Edge
Claim Edge
graph:
Suppose that
P2 requests R2
Cycle
R1
R2
P1
P3
R3
R4
P2
R1
R2
P1
P3
R3
R4
P2
Steps:
1. Find the Available Resources.
2. Construct the table:
Process
Max. Need
Hold
R1
R2
P1
P3
R3
R4
P2
Available Resources: R2
Process
Max. Need
Hold
P1
R1, R2, R3
R1, R3
P2
R3, R4
----
P3
R4
R1
cycle
R2
P1
P3
R3
R4
P2
Terminate deadlocked
processes
Free some
Resources
Memory Management
Techniques
Process need
to be
executed
Sol:
Executable file
(Size =20
memory
words)
?
Loader
Memory
loader
1.
contiguous allocation (
) block
:
) hole First Fit :
. (
) Best Fit :
. (
. Worst Fit :
.
Limit word Base Register
. register
physical. logical
Start
address of
process
Legal range
1040
20
Limit
Memory
0
OS
999
1000
1010
1040
Process
1060
1070
Executable file
(Size =20
memory
words)
Process
Process
1100
1125
Process
1150
Loader
1200
Process
1250
1255
Memory
Start
address of
process
Legal range
OS
1000
1100
1010
20
1040
Process
Limit
1070
Executable file
(Size =20
memory
words)
1100
Process
Process
1120
1125
Process
1150
Loader
1200
1250
1255
Process
Memory
Start
address of
process
Legal range
OS
1000
1150
1010
20
1040
Process
Limit
1070
Executable file
(Size =20
memory
words)
Process
1100
1125
1150
Loader
Process
Process
1170
1200
1250
1255
Process
Bootstrapping
Bootstrap program
ROM
Bootstrap Loader
.
ROM ( )
Bootstrap Program .
Bootstrap Program .
Bootstrap loader
used .
hardware (BIOS)
. Loader
. loader
:
ROM Bootstrap loader Loaders
. 0 Loader . Bootstrap program
. Absolute Loader loader
Loader
A part or OS.
Perform loading and relocation for users programs.
Bootstrap Loader
An absolute loader.
Executed when a computer is turned on or restarted.
Loads the first program to be run by the computer (usually an OS).
loads at address 0 in the memory (so that it is an absolute loader).
Disk
Range of physical
addresses
999
OS
OS
999
No Relocation
Memory
Range of logical
addresses
Bootstrap
Loader
Paging
Swapping
Contagious allocation
Swapping:
Q: Explain what is meant by swapping, Give some examples for swapping.
Sol:
A process can be swapped out of memory to disk, and then brought back into
memory for continued execution.
Ex1:
Multi-programming environment with priority scheduling
Available
27 Kb
OS (5 kb)
High Priority
process (20
kb)
Disk
OS (5 kb)
Available
27 Kb
Available
7 Kb
High
Priority
20 Kb
Contiguous Allocation
Q: Explain what is meant by contiguous allocation, what are its different
types?
Sol:
In contiguous allocation, each process is contained in a single
contiguous section of memory.
.
Simple
Method
General
Method
Simple Method
its no longer used (Explain why?) because it has various drawbacks like:
1. Degree of multiprogramming is bounded by the number of
partions.
2. Internal fragmentations.
Input Queue
(in the disk)
KB 4
KB 8
KB 9
Internal
Fragmentation
KB 7
Process 1
(7 KB)
Process 2
(9 KB)
Process 3
(8 KB)
10
KB
10
KB
10
KB
As shown
This method suffers from internal fragmentations.
The degree of multiprogramming is bounded to 3 although it can be
4.
General Method
Initially, all memory is available for user processes, and is considered as
one large block of available memory.
When a process arrives and needs memory, we search for a hole large
enough for this process using.
First Fit
Best Fit
Worst Fit
There are three different methods to find the suitable hole for
a process?:
First fit: allocate the first hole that is big enough (fastest
method).
Best fit: allocate the smallest hole that is big enough
(produces the smallest leftover hole).
Worst fit: allocate the largest hole (produces the largest
leftover hole which may be more useful than the smaller
leftover hole from a best-fit approach.
OS
Input Queue
(in the disk)
KB 4
KB 8
KB 9
KB 7
Process 4
Process 1
(4 KB)
(7 KB)
Process 5
(9
KB) 2
Process
(9 KB)
Process 3
(8 KB)
As shown:
The degree of multiprogramming changing according to the number
of processes in the memory (in ready queue).
OS
Process 4
Input Queue
(in the disk)
KB 4
KB 8
KB 9
KB 7
Process 2
Process 3
Process 9
Process 20
As shown:
This method suffers from external Fragmentations.
External
Fragmentations
Compaction
OS
Process 4
Process 4
Input Queue
(in the disk)
KB 4
KB 8
KB 9
KB 7
Process 2
Process 2
Process 3
Process 3
Process 9
Process 9
Process 20
Process 20
Compaction:
Is a movement of the memory contents to place all free memory in a one large block
sufficient to store new process.
It is a solution for the external fragmentation but it is expensive and is not always
possible.
Paging
Paging is a memory-management scheme that permits the physicaladdress space of a process to be noncontiguous.
it is commonly used in most operating systems.
Divide physical memory into fixed-sized blocks called frames.
Divide Process into blocks of same size called pages.
Use a page table which contains base address of each page in physical
memory.
Example
Page
number
0
Process
P
Page
number
Frame
number
1
2
3
Paging Example
32-byte memory, each memory word of size =1 byte (can store only one
character), the size of page (and frame also)= 4-byte.
Show how to store 4 pages process into memory using a page table.
according to your page table, what are the physical addresses
corresponding to the logical addresses 4 and 13.
Sol:
Memory size=32 Byte =32 words.
Page size = Frame size = 4 bytes =4 words.
Number of Frames = 32/4 = 8 Frames (addressed from 0 7)
Logical address
4 Page
process
Page 0 Contents
Physical address
Page 0
Frame
0
Page 1
Frame
1
Page 2
Frame
2
Page 3
Frame
3
Frame
4
Frame
5
Frame
6
Frame
7
Advantages of paging:
1.
2.
No external fragmentation.
Allow the process components to be noncontiguous.
Problems in paging:
1. A possibility of internal fragmentations that can not be used.
Q: Explain when you have internal fragmentations when using the paging
technique.
Sol:
when the contents of the last page of the process is less than the frame
size, then the remaining part of the frame will be an internal
fragmentations that can not be used.
Any Questions?