Operating System
Operating System
Progress:
Not satisfied as P1 cannot proceed
Bounded Waiting :
Process can enter into the CS in
strict alternation
• Flag – to store the intention of process regarding entering
the critical section.
Petersons Solution
• Turn – variable to give other one preference to enter into
CS
Note : Work
perfect for only
two process
Semaphore
• Semaphore is just a normal variable
that helps in achieving process
synchronization.
• They are used to enforce mutual
exclusion, avoid race conditions,
and implement synchronization
between processes.
• In order to access these semaphore
values, we use function
• Wait() or P() or Downgrade()
• Signal() or V() or Upgrade()
• Semaphores are of two
types:
1.Binary Semaphore –
This is also known as a
mutex lock. It can have
only two values – 0 and 1.
Its value is initialized to 1.
It is used to implement
the solution of critical
section problems with
multiple processes.
2.Counting Semaphore –
Its value can range over an
unrestricted domain. It is
used to control access to a
resource that has multiple
instances.
Classical Problem of synchronization
• Bounded Buffer Problem/Producer Consumer Problem
• Reader Writer Problem
• Dining Philosopher Problem
• We have a buffer of fixed size. A producer can produce an item and can place in the
buffer. A consumer can pick items and can consume them.
• We need to ensure that when a producer is placing an item in the buffer, then at the same
time consumer should not consume any item.
• In this problem, buffer is the critical section.
Producer Consumer Problem
Reader Writer Problem
•
Solution
Writer Process
Case 1 : 1 writer 2
reader
Case 2 :
Dining Philosophers Problem
Solutions to DPP
Unit 3 : Deadlock
Operation on resources
• Request: to get control on access
• Use: After request granted, the process can access
the resource.
• Release: After accessing the resource , the process
has to release the resources.
• Deadlock:
• If two or more process waiting on event that never
occur, then these process are said to be deadlock.
• E.g. – recruitment based on experience
• bat ball game between siblings
Necessary condition for Deadlock
• Deadlock can occur when all conditions are satisfied.
1. Mutual exclusion
2. Hold and wait
3. No preemption
4. Circular wait
Mutual exclusion
If one process is accessing or using any resources , no
other process is allowed to access that resource.
• Hold and wait:
One process should hold atleast one resource and wait
for at least one resource.
No pre-emption
No any resource should be pre-empted from any process.
Circular wait:
All deadlock process must wait for each other in circular
manner.
Resource Allocation Graph(Directed)
• Generally two entities
Vertices Process
• Process
Resource
• Resources s
Edge
• Request- from process to resource
• Allocation- from resource to process
Deadlock Tackling technique
• Deadlock prevention
• Deadlock avoidance
• Deadlock detection
Deadlock Prevention
Deadlock Detection
• When resource are single instances
• When resources are multiple instances
• If single instances, then draw weight for graph(WFG) ( a
variant of resource allocation graph).
• Replace resource and directly connect with the process.
• Here we see how process are waiting on each other.
• If more than one instance , then cycle in WFG is not still
sufficient for deadlock.( possibility but not guaranteed).
Here cycle does
not ensure no
deadlock
Proces Allocatio Request Available
s n
R1 R2 R1 R2 R1 R2
P1 0 1 1 0 0 0
P2 1 0 0 0
P3 1 0 0 1
P4 0 1 0 0
Page table
Logical address space = 2 ^ logical address bit(p+d)
Physical address space = 2^ physical address bit (f+d)
Time required to access content of
page
• Two memory access.
TLB (transition look aside buffer)
Multilevel Paging
• Since The page table is also stored in the main memory,
it is basically stored in frame or frames.
• So when the page table is of much more size , it
difficulty to keep track of frames.
• So we further store the page table in other page table
that contains the pages of page table.
• So first access will be done on the page table of page
table and then from page table we will directly go the
respective process page.
Segmentation
• Divide process in logically
related partitions(segments)
• Segments are scattered in
physical memory.
• Each segment are of variable
size.
Virtual Memory
• Feature of OS
• Enable to run larger
process with small main
memory.
• Based on demand paging
• Bring only those pages
which are required else
stored in secondary
memory
Page replacement policy
• FIFO
• Replace the page which come in mm first.
• Suffer from belady anomaly. – frames increase page fault also increases
Optimal policy
• Replace with that pages that is not referred for longest time in future.
• Provide minimum page fault.
• Practically into possible
Least recently used (LRU)
• Replace with pages that is not referred for longest
period of time since last allocation.
• Provides minimum page fault in practical scenario.
Most recently used(MRU)
• Replace with that page that is most recently referred.
Thrashing
• Frame allocation- equal and
proportion allocation.
• Thrashing is a condition or a
situation when the system is
spending a major portion of its time
servicing the page faults, but the
actual processing done is very
negligible.
• Causes of thrashing:
1.High degree of multiprogramming.
2.Lack of frames.
3.Page replacement policy.
Unit 5 : File and disk Management
File and file system
• Collection of related information stored in secondary storage.