+ All Categories
Home > Documents > Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating...

Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating...

Date post: 19-Dec-2015
Category:
Upload: sylvia-lynch
View: 220 times
Download: 2 times
Share this document with a friend
Popular Tags:
29
Principles of Operating Systems - I/O Structures and Storage 1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian [email protected]
Transcript
Page 1: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 1

ICS 143 - Principles of Operating Systems

Operating Systems - ReviewProf. Nalini [email protected]

Page 2: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 2

What is an Operating System?

An OS is a program that acts an intermediary between the user of a computer and computer hardware.

Major cost of general purpose computing is software. OS simplifies and manages the complexity of

running application programs efficiently.

Page 3: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 3

Operating System Views

Resource allocatorto allocate resources (software and hardware) of the

computer system and manage them efficiently.

Control programControls execution of user programs and operation of

I/O devices.

Kernel The program that executes forever (everything else

is an application with respect to the kernel).

Page 4: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 4

Operating System Spectrum

Monitors and Small KernelsBatch Systems

• Polling vs. interrupt

MultiprogrammingTimesharing Systems

• concept of timeslice

Parallel and Distributed Systems• symmetric vs. asymmetric multiprocessing

Real-time systems• Hard vs. soft realtime

Page 5: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 5

Computer System Structures

Computer System OperationI/O StructureStorage Structure

Storage Hierarchy

Hardware ProtectionGeneral System ArchitectureSystem Calls and System ProgramsCommand Interpreter

Page 6: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 6

Operating System Services

Services that provide user-interfaces to OS Program execution - load program into memory and run it I/O Operations - since users cannot execute I/O operations

directly File System Manipulation - read, write, create, delete files Communications - interprocess and intersystem Error Detection - in hardware, I/O devices, user programs

Services for providing efficient system operation

Resource Allocation - for simultaneously executing jobs Accounting - for account billing and usage statistics Protection - ensure access to system resources is controlled

Page 7: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 7

Process Management

Process - fundamental concept in OSProcess is a program in execution.Process needs resources - CPU time, memory, files/data

and I/O devices.

OS is responsible for the following process management activities.

Process creation and deletionProcess suspension and resumptionProcess synchronization and interprocess communicationProcess interactions - deadlock detection, avoidance and

correction

Page 8: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 8

Process Concept

An operating system executes a variety of programs

batch systems - jobstime-shared systems - user programs or tasksjob and program used interchangeably

Process - a program in executionprocess execution proceeds in a sequential fashion

A process containsprogram counter, stack and data section

Process Statese.g. new, running, ready, waiting, terminated.

Page 9: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 9

Process Control Block

Contains information associated with each process

• Process State - e.g. new, ready, running etc.• Program Counter - address of next instruction to be

executed• CPU registers - general purpose registers, stack pointer

etc. • CPU scheduling information - process priority, pointer• Memory Management information - base/limit

information• Accounting information - time limits, process number• I/O Status information - list of I/O devices allocated

Page 10: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 10

Schedulers

Long-term scheduler (or job scheduler) - • selects which processes should be brought into the ready

queue. • invoked very infrequently (seconds, minutes); may be slow.• controls the degree of multiprogramming

Short term scheduler (or CPU scheduler) -• selects which process should execute next and allocates

CPU.• invoked very frequently (milliseconds) - must be very fast

Medium Term Scheduler• swaps out process temporarily• balances load for better throughput

Page 11: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 11

Process Creation

Processes are created and deleted dynamically

Process which creates another process is called a parent process; the created process is called a child process.

Result is a tree of processes e.g. UNIX - processes have dependencies and form a

hierarchy.

Resources required when creating processCPU time, files, memory, I/O devices etc.

Page 12: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 12

Process Termination

Process executes last statement and asks the operating system to delete it (exit).

• Output data from child to parent (via wait).• Process’ resources are deallocated by operating system.

Parent may terminate execution of child processes.

• Child has exceeded allocated resources.• Task assigned to child is no longer required.• Parent is exiting

– OS does not allow child to continue if parent terminates– Cascading termination

Page 13: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 13

Threads

Processes do not share resources well • high context switching overhead

A thread (or lightweight process) • basic unit of CPU utilization; it consists of:

– program counter, register set and stack space

A thread shares the following with peer threads:– code section, data section and OS resources (open files,

signals)

Collectively called a task.Heavyweight process is a task with one thread.

Thread support in modern systems User threads vs. kernel threads, lightweight processes1-1, many-1 and many-many mapping

Page 14: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 14

Producer-Consumer Problem

Paradigm for cooperating processes; producer process produces information that is

consumed by a consumer process.

We need buffer of items that can be filled by producer and emptied by consumer.

• Unbounded-buffer places no practical limit on the size of the buffer. Consumer may wait, producer never waits.

• Bounded-buffer assumes that there is a fixed buffer size. Consumer waits for new item, producer waits if buffer is full.

Producer and Consumer must synchronize.

Page 15: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 15

Interprocess Communication (IPC)

Mechanism for processes to communicate and synchronize their actions.

• Via shared memory• Via Messaging system - processes communicate without

resorting to shared variables.

Messaging system and shared memory not mutually exclusive -

– can be used simultaneously within a single OS or a single process.

IPC facility provides two operations.– send(message) - message size can be fixed or variable– receive(message)

Direct vs. Indirect communication.

Page 16: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 16

CPU Scheduling

Scheduling ObjectivesLevels of SchedulingScheduling CriteriaScheduling AlgorithmsMultiple Processor SchedulingReal-time Scheduling

Page 17: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 17

Scheduling Policies

FCFS (First Come First Serve)• Process that requests the CPU FIRST is allocated the CPU

FIRST.SJF (Shortest Job First)

• Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time.

Priority • A priority value (integer) is associated with each process.

CPU allocated to process with highest priority.Round Robin

• Each process gets a small unit of CPU timeMultiLevel

• ready queue partitioned into separate queues• Variation: Multilevel Feedback queues.

Page 18: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 18

Process Synchronization

The Critical Section ProblemSynchronization HardwareSemaphoresClassical Problems of SynchronizationCritical RegionsMonitors

Page 19: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 19

The Critical Section Problem

Requirements• Mutual Exclusion• Progress• Bounded Waiting

Solution to the 2 process critical section problem

Bakery AlgorithmSolution to the n process critical section problemBefore entering its critical section, process receives a

number. Holder of the smallest number enters critical section.

Page 20: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 20

Synchronization Hardware

Test and modify the content of a word atomically - Test-and-set instruction

function Test-and-Set (var target: boolean): boolean; begin Test-and-Set := target; target := true; end;

Mutual exclusion using test and set. Bounded waiting mutual exclusion using test and

set.

“SWAP” instruction

Page 21: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - Process Synchronization 21

Mutual Exclusion with Test-and-Set

Shared data: var lock: boolean (initially false)

Process Pirepeat

while Test-and-Set (lock) do no-op;critical section

lock := false; remainder section

until false;

Page 22: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - Process Synchronization 22

Bounded Waiting Mutual Exclusion with Test-and-Set

var j : 0..n-1; key : boolean;repeat waiting [i] := true; key := true;

while waiting[i] and key do key := Test-and-Set(lock);

waiting [i ] := false; critical section j := i+1 mod n; while (j <> i ) and (not waiting[j]) do j := j + 1 mod n; if j = i then lock := false; else waiting[j] := false; remainder section

until false;

Page 23: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 23

Semaphore

Semaphore S - integer variable• used to represent number of abstract resources.• Binary vs. counting semaphores.

Can only be accessed via two indivisible (atomic) operations

wait (S): while S <= 0 do no-op S := S-1;signal (S): S := S+1;

• P or wait used to acquire a resource, decrements count • V or signal releases a resource and increments count• If P is performed on a count <=0, process must wait

for V or the release of a resource.

Block/resume implementation of semaphores

Page 24: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 24

Classical Problems of Synchronization

Bounded Buffer ProblemReaders and Writers ProblemDining-Philosophers Problem

Page 25: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - Process Synchronization 25

Readers-Writers Problem

Shared Datavar mutex, wrt: semaphore (=1); readcount: integer (= 0);

Reader processwait(mutex); readcount := readcount +1; if readcount = 1 then wait(wrt); signal(mutex); ... reading is performed ... wait(mutex); readcount := readcount - 1; if readcount = 0 then signal(wrt); signal(mutex);

Writer Processwait(wrt); … writing is performed ... signal(wrt);

Page 26: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 26

Critical Regions

High-level synchronization constructA shared variable v of type T is declared as:

var v: shared T

Variable v is accessed only inside statement

region v when B do S

where B is a boolean expression.While statement S is being executed, no other

process can access variable v.

Page 27: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 27

Monitors

High-level synchronization construct that allows the safe sharing of an abstract data type among concurrent processes.

type monitor-name = monitor variable declarations procedure entry P1 (…); begin … end; procedure entry P2 (…); begin … end; . . . procedure entry Pn(…); begin … end; begin initialization code end.

Hoare vs. Mesa Monitors

Page 28: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 28

Deadlocks

System Model Resource allocation graph, claim graph (for avoidance)

Deadlock Characterization Conditions for deadlock - mutual exclusion, hold

and wait, no preemption, circular wait.

Methods for handling deadlocksDeadlock PreventionDeadlock AvoidanceDeadlock DetectionRecovery from Deadlock

Combined Approach to Deadlock Handling

Page 29: Principles of Operating Systems - I/O Structures and Storage1 ICS 143 - Principles of Operating Systems Operating Systems - Review Prof. Nalini Venkatasubramanian.

Principles of Operating Systems - I/O Structures and Storage 29

Deadlock Prevention

If any one of the conditions for deadlock (with reusable resources) is denied, deadlock is impossible.

Restrain ways in which requests can be madeMutual Exclusion - cannot deny (important)Hold and Wait - guarantee that when a process requests a

resource, it does not hold other resources.No Preemption

• If a process that is holding some resources requests another resource that cannot be immediately allocated to it, the process releases the resources currently being held.

Circular Wait• Impose a total ordering of all resource types.


Recommended