Upload
preetham-kumar
View
215
Download
0
Embed Size (px)
Citation preview
8/7/2019 OS_Tutorial_DEP
1/29
Operating System TutorialOperating System Tutorial
Source: http://codex.cs.yale.edu/avi/osSource: http://codex.cs.yale.edu/avi/os--book/os7/slidebook/os7/slide--dir/index.htmldir/index.html
8/7/2019 OS_Tutorial_DEP
2/29
OutlineOutline
Introduction
Process and Threads
Deadlocks and Process Synchronization
Scheduling
Interrupts & System Calls
Memory Management
8/7/2019 OS_Tutorial_DEP
3/29
What is an Operating System?What is an Operating System?
A program that acts as an intermediarybetween a user of a computer and thecomputer hardware.
Operating system goals:
Execute user programs and make solvinguser problems easier.
Make the computer system convenient touse.
Use the computer hardware in an efficientmanner.
8/7/2019 OS_Tutorial_DEP
4/29
Four Components of a Computer SystemFour Components of a Computer System
8/7/2019 OS_Tutorial_DEP
5/29
OperatingOperating--System OperationsSystem Operations
Dual-mode operation allows OS to protectitself and other system components
User mode and kernel mode Mode bit provided by hardware
Provides ability to distinguish when system is running
user code or kernel codeSome instructions designated as privileged, only
executable in kernel mode
System call changes mode to kernel, return from call
resets it to user
8/7/2019 OS_Tutorial_DEP
6/29
Transition from User to Kernel ModeTransition from User to Kernel Mode
8/7/2019 OS_Tutorial_DEP
7/29
Process ConceptProcess Concept
Process
a program in execution
process execution must progress in sequentialfashion
A process includes: program counter
stack
data section
8/7/2019 OS_Tutorial_DEP
8/29
Process Control Block (PCB)Process Control Block (PCB)
8/7/2019 OS_Tutorial_DEP
9/29
Process State DiagramProcess State Diagram
8/7/2019 OS_Tutorial_DEP
10/29
CPU Switch From Process to ProcessCPU Switch From Process to Process
8/7/2019 OS_Tutorial_DEP
11/29
Representation of Process SchedulingRepresentation of Process Scheduling
8/7/2019 OS_Tutorial_DEP
12/29
Context SwitchContext Switch
When CPU switches to another process,the system must save the state of the old
process and load the saved state for thenew process
Context-switch time is overhead; thesystem does no useful work while switching
Time dependent on hardware support
8/7/2019 OS_Tutorial_DEP
13/29
Cooperating ProcessesCooperating Processes
Independent process cannot affect or beaffected by the execution of anotherprocess
Cooperating process can affect or beaffected by the execution of anotherprocess
Advantages of process cooperation
Information sharing
Computation speed-up Modularity
Convenience
8/7/2019 OS_Tutorial_DEP
14/29
ProducerProducer--Consumer ProblemConsumer Problem
Paradigm for cooperating processes,producerprocess produces
information that is consumed by aconsumerprocess
unbounded-bufferplaces no practical limiton the size of the buffer
bounded-bufferassumes that there is a
fixed buffer size
8/7/2019 OS_Tutorial_DEP
15/29
InterprocessInterprocess Communication (IPC)Communication (IPC)
Mechanism for processes to communicate and tosynchronize their actions
Message system processes communicate with eachother without resorting to shared variables
IPC facility provides two operations:
send(message) message size fixed or variable
receive(message)
If Pand Qwish to communicate, they need to:
establish a communication linkbetween them
exchange messages via send/receive
8/7/2019 OS_Tutorial_DEP
16/29
ThreadsThreads
A flow of control in a process
has access to entire process (incl. other threads)
potentially parallel execution
minimal state, so low overheads
All threads within a process share the same state and same memory space
use different stack
and can communicate with each other directly, because theyshare the same variables.
8/7/2019 OS_Tutorial_DEP
17/29
Single and Multithreaded ProcessesSingle and Multithreaded Processes
8/7/2019 OS_Tutorial_DEP
18/29
BenefitsBenefits
Responsiveness
Resource Sharing
Economy
Utilization of MP Architectures
8/7/2019 OS_Tutorial_DEP
19/29
ProcessProcess vsvs ThreadThread
Process Thread
Address Space Not Shared Shared
Stack Not Shared Not Shared
Communication IPC Direct
State
Information
Different Same
Context SwitchOverhead
Large Small
8/7/2019 OS_Tutorial_DEP
20/29
CPU SchedulerCPU Scheduler
Selects from among the processes in memory that areready to execute, and allocates the CPU to one ofthem
CPU scheduling decisions may take place when aprocess:
1. Switches from running to waiting state2. Switches from running to ready state
3. Switches from waiting to ready
4. Terminates Scheduling under 1 and 4 is nonpreemptive
All other scheduling is preemptive
8/7/2019 OS_Tutorial_DEP
21/29
DispatcherDispatcher
Dispatcher module gives control of the CPU to theprocess selected by the short-term scheduler; this
involves: switching context
switching to user mode
jumping to the proper location in the user program torestart that program
Dispatch latency time it takes for the dispatcher
to stop one process and start another running
8/7/2019 OS_Tutorial_DEP
22/29
SchedulingScheduling
Optimization Criteria
Max CPU utilization
Min turnaround time Min waiting time
Few Algorithms First Come First Serve
Shortest Job First
Priority based
Round Robin
8/7/2019 OS_Tutorial_DEP
23/29
Deadlock: Bridge Crossing ExampleDeadlock: Bridge Crossing Example
8/7/2019 OS_Tutorial_DEP
24/29
Deadlock CharacterizationDeadlock Characterization
Mutual exclusion
Hold and wait
No preemption
Circular wait
Deadlock can arise if four conditions hold simultaneously.
M h d f H dli D dl k
8/7/2019 OS_Tutorial_DEP
25/29
Methods for Handling DeadlocksMethods for Handling Deadlocks
Ensure that the system will neverenter a deadlockstate.
Allow the system to enter a deadlock state andthen recover.
D dl k P iD dl k P ti
8/7/2019 OS_Tutorial_DEP
26/29
Deadlock PreventionDeadlock Prevention
Mutual Exclusion
Hold and Wait
Require process to request and be allocated all itsresources before it begins execution
or allow process to request resources only when theprocess has none
No Preemption
Circular Wait
Restrain the ways request can be made.
I H dliI t t H dli
8/7/2019 OS_Tutorial_DEP
27/29
Interrupt HandlingInterrupt Handling
The operating system preserves the state of theCPU by storing registers and the program counter.
Determines which type of interrupt has occurred: polling
vectoredinterrupt system
Separate segments of code determine what actionshould be taken for each type of interrupt
I t t Ti liI t t Ti li
8/7/2019 OS_Tutorial_DEP
28/29
Interrupt TimelineInterrupt Timeline
C F ti f I t tCommon F nctions of Interr pts
8/7/2019 OS_Tutorial_DEP
29/29
Common Functions of InterruptsCommon Functions of Interrupts
Interrupt transfers control to the interrupt serviceroutine generally, through the interrupt vector, whichcontains the addresses of all the service routines.
Interrupt architecture must save the address of theinterrupted instruction.
Incoming interrupts are disabledwhile anotherinterrupt is being processed to prevent a lostinterrupt.
A trapis a software-generated interrupt caused eitherby an error or a user request.
An operating system is interruptdriven.