Operating System
Operating System
Functions of OS
• scheduler (time allocation to programs) ,
• synchronizer ( avoid conflicts for a
resource at the same time)
• memory manager (space allocation to
programs)
Scheduling
• Scheduling Algo
• basically utilize IO time by scheduling another
task
• Switching from one thread to another (A --> B )
can occur when
a) A is complete
b) A is blocked on IO
c) Timer interrupt forcefully preempts A
SCHEDULER
Synchronization
• Synchronization is needed as process need to
exchange information using a shared region in memory.
• However, this shared region cannot be accessed in any
manner. They needed to be accessed in correct
sequence
Synchronization
The code accessing Shared Data is called Critical
Section
No more than one process can access shared data
at a given time
Critical Sections must obey mutual exclusion
Synchronization
• How to ensure Mutual exclusion (only
one process is in critical section)
• Disable interrupts
• Test and set instructions
• Semaphore
Synchronization
• Semaphores
• Used to solve Producer Consumer
problems
• Producer consumer problems occur for
example in networks (sending and
receiving packets), unix shell IO
Synchronization
• Producer Code
down(empty_slot)
put item in buffer
up(full_slot)
Synchronization
• The above solution works for a single producer
consumer
• When multiple producers and consumers are
present , then a race condition can happen
resulting in writing to the same slot by two
different producers
• To overcome this problem, we need to make
sure that only one producer is executing "put
item in buffer". So we need to execute mutual
exclusion within a critical section
Synchronization
• down(empty_slot)
• down(mutex)
• put item in buffer
• up(mutex)
• up(full_slot)
Memory Management
• How to run process when not enough
physical memory?
• How to protect one process from
accessing another’s memory
Memory Management
• How to run process when not enough physical memory?
• How to protect one process from accessing another’s
memory
VIRTUAL MEMORY provides illusion of
more memory
Each process access only a window of
memory – due to Locality of Reference
Only a small portion of address space must
be in physical memory
Memory Management
• Each layer acts as “backing store” for layer above
disk storage
main memory
cache
registers
size
speed cost
vpn …
vpn 3
vpn 2
vpn 1
vpn 0
P1
Virtual
pages
Frame # Present bit
… …
Blk 1031 0
Blk 1030 0
Fr # 15 1
Blk 1030
…
Blk 1031
Fr #15
Fr #16
Fr # 16 1
…
PAGE TABLE
Memory Management
Page Replacement

Operating system

  • 1.
  • 2.
    Operating System Functions ofOS • scheduler (time allocation to programs) , • synchronizer ( avoid conflicts for a resource at the same time) • memory manager (space allocation to programs)
  • 3.
    Scheduling • Scheduling Algo •basically utilize IO time by scheduling another task • Switching from one thread to another (A --> B ) can occur when a) A is complete b) A is blocked on IO c) Timer interrupt forcefully preempts A
  • 4.
  • 5.
    Synchronization • Synchronization isneeded as process need to exchange information using a shared region in memory. • However, this shared region cannot be accessed in any manner. They needed to be accessed in correct sequence
  • 6.
    Synchronization The code accessingShared Data is called Critical Section No more than one process can access shared data at a given time Critical Sections must obey mutual exclusion
  • 7.
    Synchronization • How toensure Mutual exclusion (only one process is in critical section) • Disable interrupts • Test and set instructions • Semaphore
  • 8.
    Synchronization • Semaphores • Usedto solve Producer Consumer problems • Producer consumer problems occur for example in networks (sending and receiving packets), unix shell IO
  • 9.
  • 10.
    Synchronization • The abovesolution works for a single producer consumer • When multiple producers and consumers are present , then a race condition can happen resulting in writing to the same slot by two different producers • To overcome this problem, we need to make sure that only one producer is executing "put item in buffer". So we need to execute mutual exclusion within a critical section
  • 11.
    Synchronization • down(empty_slot) • down(mutex) •put item in buffer • up(mutex) • up(full_slot)
  • 12.
    Memory Management • Howto run process when not enough physical memory? • How to protect one process from accessing another’s memory
  • 13.
    Memory Management • Howto run process when not enough physical memory? • How to protect one process from accessing another’s memory VIRTUAL MEMORY provides illusion of more memory Each process access only a window of memory – due to Locality of Reference Only a small portion of address space must be in physical memory
  • 14.
    Memory Management • Eachlayer acts as “backing store” for layer above disk storage main memory cache registers size speed cost
  • 15.
    vpn … vpn 3 vpn2 vpn 1 vpn 0 P1 Virtual pages Frame # Present bit … … Blk 1031 0 Blk 1030 0 Fr # 15 1 Blk 1030 … Blk 1031 Fr #15 Fr #16 Fr # 16 1 … PAGE TABLE
  • 17.