OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer...

41
OPERATING SYSTEMS - I

Transcript of OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer...

Page 1: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

OPERATING SYSTEMS - I

Page 2: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

What is an Operating System

OS is a program that manages the computer hardware

It provides a basis for application programs and acts as an intermediary between the user and the computer hardware

Page 3: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Classification of systems (hardware)

MainframesTime-sharing SystemsDesktop SystemsMulti-processor systemsDistributed systems

Page 4: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Functions of an OS

1. Memory Manager

2. Process Manager

3. Device Manager

4. Information Manager

Page 5: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Key tasks in resource management

Keep track of the resource being managedDecide an efficient allocation scheme for

the resourceAllocate the resourceReclaim the resource when it is not

needed

Page 6: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

OS as a Process Manager

What is a process? It is a program in execution, stored in the main memory, utilizing system resources.

Need of Process Management: A multi-user/multi-programming environment

has several processes running concurrently with the CPU switching between them.

The OS manages their execution.

Image inspired by Galvin

Page 7: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

How does it manages this?

Each process is in a certain state at any instant of time: New process that has just come in for execution A process that is ready to run A process that is already running A process that is waiting for some event/

resource and its execution is paused A process that has terminated

Page 8: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

How does the OS keep track of process states? The OS maintains the state of each process in a

special structure called the Process Control Block (PCB)

The main components of the PCB are: Pointer to the location of the program Process state Process ID Program Counter Registers Memory limits List of open files CPU scheduling information Device usage information

Page 9: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Process switching mechanism

When the CPU switches from one process to another, the state of the currently executing process is saved in its PCB.

The state of the next process is loaded from its PCB and the CPU starts working on it.

Page 10: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Process Scheduling

Determining which process will execute when, and for how long is called process scheduling

For this, the OS maintains several Queues: Job Queue Ready Queue Device Queue

Page 11: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Types of schedulers:

Long Term Scheduler Handles fresh processes Least frequent Must select a good mix of CPU and IO intensive

programs

Medium Term Scheduler Creates batches for the short term scheduler Swaps out inactive processes

Short Term Scheduler Picks out the deserving process for giving the CPU Most frequently used, must be very fast

Page 12: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Operations on a process:

Process CreationProcess termination

Page 13: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

The dispatcher

It is that component that performs the actual CPU control transfer from one process to another.

The dispatcher latency has a major impact on system efficiency

Page 14: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Pre-emption

Preemption is a policy which requires a lot of thought before implementing

With this enabled, a high priority process can replace a running process

Without this, we must rely on the process to voluntarily give up the CPU control

Page 15: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

CPU scheduling policies

First Come First ServedShortest job FirstPriority SchedulingRound Robin SchedulingMultilevel Queue SchedulingMultiprocessor schedulingRealtime scheduling

Page 16: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Deadlocks

A deadlock is like a traffic jam on a roundabout

A process P1 has a resource for which another process P2 is waiting. Now P1 requests for a resource which is currently allocated to P2. Now both will wait for each other forever.

This 2 process example can be extended to any number of processes

Page 17: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Conditions necessary for deadlock

Mutual ExclusionHold & WaitNo preemptionCircular wait

Page 18: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Deadlock handling

Deadlock prevention Break one of the conditions

Deadlock avoidance Intelligent allocation of resources

Detection & Repair Periodically check for a deadlock and break it

Page 19: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Process Synchronization

Co-operating Processes may be sharing some data

Concurrent access to shared data may cause data inconsistencies

We must avoid this race condition

Page 20: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Critical Section

Each process has a segment of code in which it is modifying a shared piece of data. This section is called the Critical Section.

Synchronization can be maintained by ensuring that no two processes are in their critical sections at the same time.

Page 21: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Semaphores

Semaphores are like signal flags which can be used to mange the critical section

Semaphores can be accessed only by 2 atomic operations : signal & wait

Page 22: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Classical Synchronization Problems

The Bounded Buffer ProblemThe Readers-Writes ProblemThe Dining-Philosophers Problem

Page 23: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Memory Management

A program can execute only if it is loaded in the main memory

In multiprogramming, several processes have to run simultaneously

Loading and unloading the process, responding to memory allocation requests, and de-allocation are the jobs OS performs as a Memory Manager.

Image inspired by Galvin

Page 24: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Logical and Physical Memory

Logical memory : The image of the memory as seen by the process running on the CPU

Physical memory : The real hardware memory, which is not always directly presented to the process

Page 25: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Dynamic loading

Here parts of the program are loaded only on requirement

Overlays

Old method, implemented by the programmer to allow for larger programs

Page 26: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Swapping

To increase multiprogramming, we can move waiting processes from Physical memory to backing store device to make room for new processes.

Processes in the backing store can similarly be loaded back into memory

This is called swapping.

Page 27: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Contiguous Memory requirement

Almost all programs want to have contiguous memory allocated to them

This complicates the task of memory management as we have to deal with problems like fragmentation etc.

We will see later how they are partially removed by techniques like paging and segmentation

Page 28: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Memory Protection

We have to protect the Operating System from user processes, and also protect user processes from one another

We can provide this protection by using relocation registers.

Page 29: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Memory Allocation

Empty blocks of various sizes are scattered around the memory at any given time

When a process is to be loaded in the memory, we have to decide where to place it. We use these three algorithms:

1. First Fit2. Best Fit3. Worst Fit

Page 30: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Fragmentation

If the sum of all the free blocks is larger than the process size, but no single block is large enough to accommodate the process, the process cannot be loaded.

This is known as Fragmentation (more precisely External Fragmentation)

External Fragmentation can be removed by regular compaction.

Internal Fragmentation can be better understood with paging

Page 31: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Paging

Paging is a scheme which permit the physical address space of a process to be non-contiguous.

Physical memory is split into fixed size blocks called frames.

The logical memory of the process is also broken into blocks of same size called frames.

Each process is allocated the required number of frames.

The wastage of space inside the final page is called internal fragmentation.

Page 32: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Page Table

The mapping of pages to frames is maintained in the page table.

Segmentaion

Segmentation is similar to paging with variable sized pages.This makes it more space efficient, but more difficult to manage.

Page 33: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Virtual Memory

Virtual Memory allows a process to start execution with only a few of its pages loaded in the memory.

Pages requested by the process which are not loaded cause a Page Fault and the page must be loaded now.

Page 34: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Page Replacement

As more pages are loaded, memory tends to get full, so some pages need to be unloaded to the disk.

The following algorithms help to decide which pages to offload: FIFO Page Replacement Optimal Page Replacement Least Recently Used (LRU) Page Replacement

Page 35: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Global and Local Page Replacement

With Global Page Replacement, a process can replace the pages of any process.

In Local Page Replacement the process can replace only its own pages.

Page 36: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Thrashing

With global page replacement, a condition can occur where the number of page faults, increases very high, with most of the processes waiting for their pages to be loaded. The scheduler loads up more processes to try to increase CPU utilization, which further aggravates the problem, decreasing the throughput.

Page 37: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Device Management

Dedicated device : A device that can be used one at a time only. Eg. a card reader

Shared Device : Two or more users can simultaneously use the device.

Virtual Device : This converts a dedicated device to a shred device by employing spooling technique.

Image inspired by Galvin

Page 38: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Device Characteristics

The device can be an IO device.The device can be a storage device.

Access time: Serial Device (Eg Tape Drive) Completely Direct Serial Access Device (grid

memory) Direct Access Device (Hard Disk)

Page 39: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Disk Scheduling

With several requests coming for disk access, it is necessary to properly organize retrievals for maximum efficiency.

Disk Scheduling Algorithms: FCFS SSTF Scan scheduling C-scan scheduling Look Scheduling C-look

Page 40: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Information Management

File Concept: There are many storage mediums available. The OS abstracts the physical properties of the storage device to define a logical storage unit – the file.

Page 41: OPERATING SYSTEMS - I. What is an Operating System OS is a program that manages the computer hardware It provides a basis for application programs and.

Directory Structure

Single LevelTwo LevelTree structureGraph directories