Operating System Overview
Operating System Overview
1
Objectives and Functions
2
Operating System
• A program that controls the execution of application
programs
• An interface between applications and hardware
3
Operating System as User/ Computer Interface
Application programs
Application
programming interface
Application Libraries/utilities Software
binary interface
Operating system
Instruction Set
Architecture
Execution hardware
Memory
System interconnect
translation Hardware
(bus)
I/O devices
Main
and
memory
networking
5
Operating System Services
• Program development
• Program execution
• Access I/O devices
• Controlled access to files
• System access
• Error detection and response
• Accounting
6
The Operating System as Resource Manager
7
Operating System
as Resource Manager
8
Evolution and Major
Archievement of Operating
Systems
9
Ease of Evolution of Operating Systems
New services
Fixes
▪ OS need regularly update for certain
requirements on its design.
10
Evolution of
Operating Systems
▪ Stages include:
Time
Sharing
Multiprogrammed Systems
Batch Systems
Simple Batch
Systems
Serial
Processing
11
Major Achievements
12
Process
A program in execution
13
Process Execution States
• For convenience, we describe a process as being in one of several
basic states.
• Most basic:
• Running
• Ready
• Blocked (or sleeping)
14
Process State Transition Diagram
preempt
ready running
dispatch
blocked
15
Other States
• New
• Exit
• Suspended (Swapped)
– Suspended blocked
– Suspended ready
16
Processes and Threads
• Traditional processes could only do one thing at a time – they were
single-threaded.
• Multithreaded processes can (conceptually) do several things at once
– they have multiple threads.
• A thread is an “execution context” or “separately schedulable” entity.
17
Threads
• Several threads can share the address space of a single process, along
with resources such as files.
• Each thread has its own stack, PC, and TCB (thread control block)
• Each thread executes a separate section of the code and has private data
• All threads can access global data of process
18
Threads versus Processes
• If two processes want to access shared data structures, the OS must
be involved.
• Overhead: system calls, mode switches, context switches, extra execution
time.
• Two threads in a single process can share global data automatically –
as easily as two functions in a single process.
19
Causes of Errors
21
Main Processor
Memory Registers
Process index i
PC
i
Process Management Process
list
j
Base
Limit
b
h
Other
registers
Context
Process
▪ The entire state of the A
Data
23
Scheduling Algorithms:
• FCFS (first-come, first-served): non-preemptive:
processes run until they complete or, in multi-
programmed systems, until they block themselves
for event wait.
• RR (round robin): preemptive FCFS, based on time
slice
• Time slice = length of time a process can run before
being preempted
• Return to Ready state when preempted
24
Scheduling Goals
• Optimize turnaround time and/or response time
• Optimize throughput
• Avoid starvation (be “fair” )
• Respect priorities
• Static
• Dynamic
25
Memory Management
Automatic
Support of Protection
Process allocation Long-term
modular and access
isolation and storage
programming control
management
26
Virtual Memory
27
Paging
28
A.1
A.0 A.2
0 0
A.5
1 1
2 2
B.0 B.1 B.2 B.3
3 3
4 4
5 5
6 6
A.7
7 User
A.9
8 program
B
9
A.8
10
User
program
A
B.5 B.6
Disk
Address
Secondary
Memory
31
Scheduling and
Resource Management
• Key responsibility of
an OS is managing
resources Efficiency
Fairness
• Resource allocation
policies must consider:
Differential
responsiveness
32
Operating System
Service Call Service
from Process Call
Handler (code)
Pass Control
to Process
• Microkernel architecture
• Multithreading
• Symmetric multiprocessing
• Distributed operating systems
• Object-oriented design
34
Microkernel Architecture
• The approach:
Well suited to a
Simplifies Provides
distributed
implementation flexibility
environment
35
Multithreading
Thread Process
• Technique in
which a process,
executing an Dispatchable unit of work
A collection of one or more
threads and associated system
application, is resources
divided into
threads that can By breaking a single application
36
Symmetric
Multiprocessing (SMP)
• Term that refers to a computer hardware architecture and also to
the OS behavior that exploits that architecture
• The OS of an SMP schedules processes or threads across all of
the processors
• The OS must provide tools and functions to exploit the
parallelism in an SMP system
• Multithreading and SMP are often discussed together, but the
two are independent facilities
• An attractive feature of an SMP is that the existence of multiple
processors is transparent to the user
37
SMP Advantages
Process 1
Process 2
Process 3
Process 1
Process 2
Process 3
Blocked Running
Distributed Operating
System Object-Oriented Design
40
Fault Tolerance
41
Fault Tolerance
42
Fundamental Concepts
43
44
Class Availability Annual Downtime
Continuous 1.0 0
Fault Tolerant 0.99999 5 minutes
Fault Resilient 0.9999 53 minutes
High Availability 0.999 8.3 hours
Normal Availability 0.99 - 0.995 44-87 hours
45
Faults
46
Fault Categories
• Permanent
• A fault that, after it occurs, is always present
• The fault persists until the faulty component is replaced or repaired
• Temporary
• A fault that is not present all the time for all operating conditions
• Can be classified as
• Transient – a fault that occurs only once
• Intermittent – a fault that occurs at multiple, unpredictable times
47
Virtual Machine Approach
48
Interprocess Communication (IPC)
49
Process Synchronization -
• Event ordering – insure that event 2 in process
A happens before event 4 in process B.
• Mutual exclusion - when one process is using a
shared resource, no other process should be
allowed to access the same resource. This is
also referred to as the critical section problem.
50
Mutual Exclusion
• A critical section is the code that accesses shared
data or resources.
• A solution to the critical section problem must
ensure that only one process at a time can execute
its critical section (CS).
• “lock” the critical section.
• Two separate shared resources can be accessed
concurrently.
51
Synchronization
• Processes and threads are responsible for their
own synchronization, but programming languages
and operating systems may have features to help.
• Virtually all operating systems provide some form
of semaphore, which can be used for mutual
exclusion and other forms of synchronization such
as event ordering.
52
Semaphores
• Definition: A semaphore is an integer variable (S) which can only be
accessed in the following ways:
• Initialize (S)
• P(S) // {wait(S)}
• V(S) // {signal(S)}
• The operating system must ensure that all operations are indivisible,
and that no other access to the semaphore variable is allowed
53
Other Mechanisms for Mutual Exclusion
• Spinlocks: a busy-waiting solution
in which a process wishing to enter a critical section continuously
tests some lock variable to see if the critical section is available.
Implemented with various machine-language instructions
• Disable interrupts before entering CS, enable after leaving
54
Deadlock
• A set of processes is deadlocked when each is in the Blocked state
because it is waiting for a resource that is allocated to one of the
others.
• Deadlocks can only be resolved by agents outside of the deadlock
55
Deadlock versus Starvation
• Starvation occurs when a process is repeatedly denied access to a
resource even though the resource becomes available.
• Deadlocked processes are permanently blocked but starving
processes may eventually get the resource being requested.
• In starvation, the resource being waited for is continually in use, while
in deadlock it is not being used because it is assigned to a blocked
process.
56
Causes of Deadlock
57
Deadlock Management Strategies
• Prevention: design a system in which at least one of the 4 causes can
never happen
• Avoidance: allocate resources carefully, so there will always be
enough to allow all processes to complete (Banker’s Algorithm)
• Detection: periodically, determine if a deadlock exists. If there is one,
abort one or more processes, or take some other action.
58
End of Operating System Review
59